Home All Groups Group Topic Archive Search About

Multithreading and ActiveX

Author
23 Mar 2006 1:35 PM
Yeti
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!!

Author
23 Mar 2006 3:23 PM
Armin Zingler
Show quote Hide quote
"Yeti" <Y***@discussions.microsoft.com> schrieb
> 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
Author
23 Mar 2006 3:51 PM
Armin Zingler
Show quote Hide quote
"Armin Zingler" <az.nospam@freenet.de> schrieb
> "Yeti" <Y***@discussions.microsoft.com> schrieb
> > 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.

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
Author
23 Mar 2006 4:10 PM
Yeti
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

Show quoteHide quote
"Armin Zingler" wrote:

> "Armin Zingler" <az.nospam@freenet.de> schrieb
> > "Yeti" <Y***@discussions.microsoft.com> schrieb
> > > 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.
>
> 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
>
>
Author
23 Mar 2006 4:17 PM
Armin Zingler
"Yeti" <Y***@discussions.microsoft.com> schrieb
> 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
Author
23 Mar 2006 7:15 PM
Yeti
Sounds good...I'm looking into it..thanks

Show quoteHide quote
"Armin Zingler" wrote:

> "Yeti" <Y***@discussions.microsoft.com> schrieb
> > 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
>
>