By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,524 Members | 1,519 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,524 IT Pros & Developers. It's quick & easy.

Multithreading and ActiveX

P: n/a
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!!

Mar 23 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
"Yeti" <Ye**@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

Mar 23 '06 #2

P: n/a
"Armin Zingler" <az*******@freenet.de> schrieb
"Yeti" <Ye**@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

Mar 23 '06 #3

P: n/a
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

"Armin Zingler" wrote:
"Armin Zingler" <az*******@freenet.de> schrieb
"Yeti" <Ye**@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

Mar 23 '06 #4

P: n/a
"Yeti" <Ye**@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

Mar 23 '06 #5

P: n/a
Sounds good...I'm looking into it..thanks

"Armin Zingler" wrote:
"Yeti" <Ye**@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

Mar 23 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.