Multithreading and ActiveX

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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 don't 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!!
 
Yeti said:
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 don't 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!!


If you use the ActiveX control, you must use the STAThread (or no)
attribute.

Why do you need MTAThread? You can create threads without this attribute.


Armin
 
Armin Zingler said:
If you use the ActiveX control, you must use the STAThread (or no)
attribute.

Skip the "(or no)" words. Default is MTAThread for the main procedure of the
startup thread.
Why do you need MTAThread? You can create threads without this
attribute.




Armin
 
Thanks for getting back to me Armin. I need to use the MTAThread so that I
can subscribe to an OPC server. Any workarounds or should I just delete all
the ActiveX's?- Owen
 
Yeti said:
Thanks for getting back to me Armin. I need to use the MTAThread so
that I can subscribe to an OPC server. Any workarounds or should I
just delete all the ActiveX's?- Owen


Why not start another thread that communicates with the OPC server? If you
do it, be aware of what the docu says: You must set the ApartmentState
property of the other thread before you start it.


Armin
 
Sounds good...I'm looking into it..thanks

Armin Zingler said:
Why not start another thread that communicates with the OPC server? If you
do it, be aware of what the docu says: You must set the ApartmentState
property of the other thread before you start it.


Armin
 
Back
Top