2023R1_SCOverlayGraphOnEvent Sample Issue

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);
        }
    }
}

Milestone Development might investigate whether backwards compatibility has been broken. Please try to see if you can do a workaround using this method - virtual void VideoOS.Platform.ClientControl.CallOnUiThread (Action actionToBeInvoked)

https://doc.developer.milestonesys.com/html/index.html?base=miphelp/class_video_o_s_1_1_platform_1_1_client_control.html&tree=tree_search.html?search=callonui

Investigating we found that the sample actually uses what we suggested as workaround.

If you look further in the OverlayGraphOnEventBackgroundPlugin class you can see that in the ClearOverlay() method calls to imageViewerAddOn are being wrapped in a “ClientControl.Instance.CallOnUiThread()”