( InvalidCastException) , .
, STAThread. Main [STAThread].
, . , , , - async, Thread, .
If you create new threads (it doesn’t matter if you create it using ThreadPool or an async delegate), they are always MTA threads . Thus, you need to create your own thread and start it explicitly as STAThread.
You can do it as follows:
var thread=new Thread( () => method() );
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
I think you need to dig in this direction to find a mistake.
source
share