开发者

Is there a generic 'FuncSTA' for invoking delegates by a STA thread?

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜