0

I have an ASP.NET application and need to use some COM 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()
Xaqron
  • 29,931
  • 42
  • 140
  • 205

1 Answers1

0

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().

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964