Any workarounds for "The calling thread must be STA, because many UI components require this." error?

Hi, I am currently creating a plugin that would show a camera window (via ShowCamerasInFloatingWindowCommand) when a link is click on a website which is in a Workspace that contains a ChromiumWebBrowser tag.

The link throws a Javascript command in which the plugin catches, but I get a STA error: “The calling thread must be STA, because many UI components require this.” in Milestone Xprotect Client. Here a some code snippets.

//this is in public partial class ProjectWorkSpaceViewItemWpfUserControl : ViewItemWpfUserControl
public ProjectWorkSpaceViewItemWpfUserControl()
        {
            InitializeComponent();
            CefSharpSettings.LegacyJavascriptBindingEnabled = true;
            this.Browser.RegisterJsObject("metagrated", proxy);
        }
 
 
//This is the Execution of the Javascript command.
public void Execute()
{
                var data = new ShowCamerasInFloatingWindowData();
                data.Cameras = new List<Item>() { cameraItem };
                data.BrowseTime = DateTime.Now;
                data.Mode = Mode.ClientPlayback;
 
                EnvironmentManager.Instance.SendMessage(new Message(
                    MessageId.SmartClient.ShowCamerasInFloatingWindowCommand)
                {
                    Data = data
                });
}

Hi. This problem is not SDK but general .NET thing. Try invoking your code into the UI dispatcher:

   public void Execute()

   {

       this.BeginInvoke((Action)delegate ()

       {

           var data = new ShowCamerasInFloatingWindowData();

           data.Cameras = new List<Item>() { cameraItem };

           data.BrowseTime = DateTime.Now;

           data.Mode = Mode.ClientPlayback;

           EnvironmentManager.Instance.SendMessage(new VideoOS.Platform.Messaging.Message(

               MessageId.SmartClient.ShowCamerasInFloatingWindowCommand)

           {

               Data = data

           });

          });

   }

The BeginInvoke method is on any System.Windows.Forms.Control.

On SC you can also use ClientControl.Instance.CallOnUiThread(() => { code }

Freddy