Multithreading and ActiveX

Yeti

New member
Joined
Mar 22, 2006
Messages
1
Hey everyone, I am modifying code upgraded from VB 6 to 2005. I need to run the 2005 code in the MTA mode so I set a sub main procedure in my module which runs first when the program starts:

Public theApplicationForm As New Form1

<MTAThread()> Public Sub main()
Application.Run(theApplicationForm)
End Sub

However, when this launches the Form1, I receive the following runtime error:
{"ActiveX control 6262d3a0-531b-11cf-91f6-c2863c385e30 cannot be instantiated because the current thread is not in a single-threaded apartment."}

I dont know how to proceed from here. I realize that the ActiveX component is something old VB6 code still being used..I believe it is an MSFlexGrid. How do I run my program as multithreaded successfully? MANY THANKS!!
 
As far as I know ActiveX single/multithreading is not related to .net multithreading. The ActiveX single / multi threaded appartment is only related to the threads on which COM objects can be used. The application can still use other threads, however the COM objects cant be accessed from these other threads.

So in .NET you can declare your application to be a single threaded appartment application (using STAThread instead of MTAThread) but still use back ground threading and other threading mechanisms. Only thing you probably have to be carefull with is that the ActiveX object (and all its attributes) are probably not usable from a background thread. But Im not sure, perhaps .NET has a mechanism build in to do this correctly ;).
 
Back
Top