469,910 Members | 1,553 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

System.Threading.ThreadStateException

hi all,
i faced an error in my project:
"An unhandled exception of type
'System.Threading.ThreadStateException'
occurred in system.windows.forms.dll
Additional information: Could not instantiate ActiveX control
'648a5600-2c6e-101b-82b6-000000000014' because the current thread is
not in
a single-threaded apartment."

after i set as below:
Thread.CurrentThread.ApartmentState = ApartmentState.STA

other error occured:
Fail to set ApartmentState
i already put
<STAThread()_
PublicSub Main()

for more detail about my error:

<STAThread()_
PublicSub Main()
.....
Thread.CurrentThread.SetApartmentState(ApartmentSt ate.STA) -error
(fail to set.....)
InitializeComponent()
.....

PrivateSub InitializeComponent()
....
Me.ScanSerial = New AxMSCommLib.AxMSComm
....

anyone know why?
please help...Thanks

Jan 30 '07 #1
1 5022
On Jan 30, 3:49 am, "Pooh" <hiank...@gmail.comwrote:
hi all,
i faced an error in my project:
"An unhandled exception of type
'System.Threading.ThreadStateException'
occurred in system.windows.forms.dll
Additional information: Could not instantiate ActiveX control
'648a5600-2c6e-101b-82b6-000000000014' because the current thread is
not in
a single-threaded apartment."

after i set as below:
Thread.CurrentThread.ApartmentState = ApartmentState.STA

other error occured:
Fail to set ApartmentState

i already put
<STAThread()_
PublicSub Main()

for more detail about my error:

<STAThread()_
PublicSub Main()
....
Thread.CurrentThread.SetApartmentState(ApartmentSt ate.STA) -error
(fail to set.....)
InitializeComponent()
....

PrivateSub InitializeComponent()
...
Me.ScanSerial = New AxMSCommLib.AxMSComm
...

anyone know why?
please help...Thanks
Hmmm, it looks like your trying to use the old ms com control. Are
you trying to do some serial communication of some type? The reason I
ask is that as of .NET 2.0, this ability is built into the framework.
Look at System.IO.Ports.SerialPort.

Anyway, as to your current problem - you can't set the apartment state
of a running thread. So, you can't call

Thread.CurrentThread.SetApartmentState(ApartmentSt ate.STA)

On your main thread - it is by definition already started. Setting
the STAThread attribute is how you set the main threads threading
model. You can confirm this - just check the current threads
apartmentstate (GetApartmentState).

Anyway - i would look at using the built in serial stuff. I've heard
of people having issues with the COM control :) If you must use it,
then we might need to do a little more in depth analysis as to why
your getting the apartmentstate error.

--
Tom Shelton

Jan 30 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Jaret Brower | last post: by
2 posts views Thread by Vjay77 | last post: by
2 posts views Thread by Stressed Out Developer | last post: by
reply views Thread by angshuman.agarwal | last post: by
3 posts views Thread by =?Utf-8?B?TWFyayBDaGFubmluZw==?= | last post: by
2 posts views Thread by BruceWho | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.