I have an ASP.NET
application and need to use some C开发者_开发技巧OM
components inside it.
I need a wrapper class over Func
or Action
which creates a new STA
thread and run the delegate with that thread or something like this. Do you know such a class or library out of the box or a sample code ?
CodeUsingComComponent.InvokeSTA()
No such method exists.
You can write one yourself:
public static void InvokeSTA(this ThreadStart method) {
var thread = new Thread(method);
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
}
If you want to invoke it synchronously, add thread.Join()
.
精彩评论