Threading-freezing problem with Window Forms and COM ActiveX Objects

J

jjrwork

Hello,

This is the first time I post a message so first of all my apologize about
my poor language.

I have a problem:

I have a Windows Forms (STA) app in which I have to use an ActiveX for a
third partner which takes several seconds to perform their operations. If I
run this methods directly my User Interface becomes "frozen", so I run this
ActiveX/COM in a new thread following this example:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwinforms/html/AsyncUI.asp

it works OK if in the thread function I create the COM object, use it, and
destroy. But if I create the COM object in my UI Thread and pass the object
to the new thread to use it, the application UI becomes frozen.

I need to maintain the reference of the COM object to use it along the
application lifetime (the initialization is very slow), so I need a
solution.

I have search on the Internet and I found someone who have the exactly the
same problem, but I don't understand the solution.

http://www.thescripts.com/forum/thread256039.html

Can you give me an example or a piece of advice? I'm absolutely desperate...

Thanks in advance.
Jorge
 
S

Stoitcho Goutsev \(100\)

jjrwork,

In the STA scenarios the com object uses the message loop to do the thread
switching so all the code inside the ActiveX is executed in the same thread.
This is easier to progam and is the most used techniques when developing
ActiveX objects.

What that means for you? Your activeX is created in the main UI thread and
uses your UI thread's message pump. Doesn't mather what thread calls methods
in this ActiveX component all the computation will happen in the main UI
thread and will block the UI of the whole application for the duration of
the call.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top