My application need to use some COM objects in MTA (COM object will use UI element), so I defined my app as MTA:
[global::System.MTAThreadAttribute]
static void Main(string[] args)
{
XamlCheckProcessRequirements();
global::WinRT.ComWrappersSupport.InitializeComWrappers();
global::Microsoft.UI.Xaml.Application.Start((p) =>
{
var context = new global::Microsoft.UI.Dispatching.DispatcherQueueSynchronizationContext(global::Microsoft.UI.Dispatching.DispatcherQueue.GetForCurrentThread());
global::System.Threading.SynchronizationContext.SetSynchronizationContext(context);
new App();
});
}
However, after defining it, i cannot do a copy-paste action on any TextBox in app.
When I checked with Clipboard.SetContent(copyData);
it throws an exception: Activating a single-threaded class from MTA is not supported
So, How can i solve this problem?