开发者

.Net Com Interop Create Instance Slow

I have a .net 4 application that uses a Com Dll to send SMS messages. I used TlbImp to create the interop assembly and that is what is referenced in the application.

When I try to create an instance of this class, it takes a really long time (2-5 seconds).

开发者_C百科

I ran performance profile in VS 2010 and the call that takes the longest by far is System.Activator.CreateInstance().

I am looking for tips on how to debug or gotchas with using Com Interop.


What COM Apartment type is the thread you are creating the object on?

If it is you main application thread and you do not mark you Main entry point with the STAThreadAttribute you will be running in an MTA. If you use the attribute your thread will be in an STA. For other threads, you can set the apartment type using Thread.SetApartmentState before starting the thread.

If your COM object is registered with a different apartment model than you are using, you'll incur the overhead of a new thread/apartment being spun up, the object being created in that other apartment, and all communication occurring via proxy/stubs rather than direct invocations on the COM object.

This could be causing some performance issues.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜