467,894 Members | 1,694 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,894 developers. It's quick & easy.

Multithreading and ActiveX

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
  • viewed: 5433
Share:
5 Replies
"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
"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
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
"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
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.

Similar topics

15 posts views Thread by Mark Sisson | last post: by
16 posts views Thread by Robert Zurer | last post: by
20 posts views Thread by Cybertof | last post: by
5 posts views Thread by sarge | last post: by
2 posts views Thread by Rich | last post: by
5 posts views Thread by sandy82 | last post: by
4 posts views Thread by boo73uk | last post: by
7 posts views Thread by Ray | last post: by
reply views Thread by MrMoon | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.