We wrote a popular plugin based on an old version of SCOverlayGraphOnEvent. But when upgrading to 2023R1, we get “The calling thread cannot access this object because a different thread owns it.”. And we found that the new Milestone 2023R1_SCOverlayGraphOnEvent sample produces the same Exception, when adding just adding a reference to one property of a ImageViewerAddOn.
Question: How can I set up a delegate call to be able to reference properties of the “addOn” variable?
Please review the code copied from the SCOverlayGraphOnEvent sample …
//Go through all registered AddOns and identify the one we are looking for
foreach (ImageViewerAddOn addOn in tempList)
{
OverlayObject oo;
if (_dicAddOnOverlayObjects.TryGetValue(addOn, out oo))
{
// THIS IS INSIDE: public class OverlayGraphOnEventBackgroundPlugin : BackgroundPlugin
#region ONLY CODE I ADDED TO SCOverlayGraphOnEvent SAMPLE.
if (addOn == null || addOn.Size == null)
// addOn.Size reference causes Exception:
// "The calling thread cannot access this object because a different thread owns it."
;
#endregion
DateTime endTime = oo.StartTime.AddMilliseconds(_keepOverlayPeriod);
if (endTime < DateTime.UtcNow)
{
ClearOverlay(addOn);
_dicAddOnOverlayObjects.Remove(addOn);
}
}
}