场景:
第三方COM组件不支持跨线程调用。
应用程序启动需要启动:
1.UI
2.HttpServer
启动HTTPServer的时候会启动第三方的组件 UI访问HttpServer,HttpServer调用第三方接口然后response。问题:
由于第三方组件不支持跨线程调用,导致程序卡死。
异常:
The CLR has been unable to transition from COM context 0x4ee0f8 to COM context 0x4ee268 for 60 seconds. The thread that owns the destination context/apartment is most likely either doing a non pumping wait or processing a very long running operation without pumping Windows messages. This situation generally has a negative performance impact and may even lead to the application becoming non responsive or memory usage accumulating continually over time. To avoid this problem, all single threaded apartment (STA) threads should use pumping wait primitives (such as CoWaitForMultipleHandles) and routinely pump messages during long running operations.请提供dispatch的例子,谢谢
第三方COM组件不支持跨线程调用。
应用程序启动需要启动:
1.UI
2.HttpServer
启动HTTPServer的时候会启动第三方的组件 UI访问HttpServer,HttpServer调用第三方接口然后response。问题:
由于第三方组件不支持跨线程调用,导致程序卡死。
异常:
The CLR has been unable to transition from COM context 0x4ee0f8 to COM context 0x4ee268 for 60 seconds. The thread that owns the destination context/apartment is most likely either doing a non pumping wait or processing a very long running operation without pumping Windows messages. This situation generally has a negative performance impact and may even lead to the application becoming non responsive or memory usage accumulating continually over time. To avoid this problem, all single threaded apartment (STA) threads should use pumping wait primitives (such as CoWaitForMultipleHandles) and routinely pump messages during long running operations.请提供dispatch的例子,谢谢
不行,因为COM组件的创建者不是COM组件的调用者,肯定要跨线程调用的
{
this._thread = new Thread(Login);
this._thread.SetApartmentState(ApartmentState.STA);
this._thread.Start();
}
win32 的COM是对线程的支持有点问题,但是对进程支持还不错。
如果没有办法解决这个线程问题,那么你就得改改你的设计思路了。