473,722 Members | 2,295 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

System.Threadin g.ThreadStateEx ception

hi all,
i faced an error in my project:
"An unhandled exception of type
'System.Threadi ng.ThreadStateE xception'
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.CurrentT hread.Apartment State = 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.CurrentT hread.SetApartm entState(Apartm entSt ate.STA) -error
(fail to set.....)
InitializeCompo nent()
.....

PrivateSub InitializeCompo nent()
....
Me.ScanSerial = New AxMSCommLib.AxM SComm
....

anyone know why?
please help...Thanks

Jan 30 '07 #1
1 5184
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.Threadi ng.ThreadStateE xception'
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.CurrentT hread.Apartment State = 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.CurrentT hread.SetApartm entState(Apartm entSt ate.STA) -error
(fail to set.....)
InitializeCompo nent()
....

PrivateSub InitializeCompo nent()
...
Me.ScanSerial = New AxMSCommLib.AxM SComm
...

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.CurrentT hread.SetApartm entState(Apartm entSt 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 (GetApartmentSt ate).

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
14462
by: Warren | last post by:
I don't understand what's going on in the following program. I believe it should simply create a form with a browser in it and navigate that browser to Google. However, the constructor for the WebBrowser is throwing a ThreadStateException saying ActiveX control '8856f961-340a-11d0-a96b-00c04fd705a2' cannot be instantiated because the current thread is not in a single-threaded apartment. Any ideas what's going on? using System; using...
5
5375
by: Adam Clauss | last post by:
I am creating a plugin for MS Outlook. Upon clicking a toolbar button, I create series of threads (variable number each time). Within each thread, I start a form using Application.Run(...). This form contains the Web Browser ActiveX control. Upon creating the form, I get a ThreadStateException "Could not instantiate ActiveX control ..... because the current thread is not in a single-threaded apartment." Right now, I'm using a ThreadPool...
5
2498
by: Jaret Brower | last post by:
I'm trying to get Clipboard data from across the network to get a screenshot. I hit a button on the server, it sends a request to the client, when the client get's the request it does a SendKeys.SendWait("%{PRTSC}") , then when i make the call Clipboard.GetImage() a ThreadStateException is thrown. The attribute is defined on the main. Any ideas?
2
2246
by: Vjay77 | last post by:
In this code: Private Sub downloadBtn_Click(ByVal sender As Object, ByVal e As System.EventArgs) If Not (Me.downloadUrlTextBox.Text = "") Then Me.outputGroupBox.Enabled = True Me.bytesDownloadedTextBox.Text = "" Me.totalBytesTextBox.Text = ""
2
2355
by: Stressed Out Developer | last post by:
We have an application that has a 200 count loop that does the following: ' Each time thru the loop we pass the next IP Address is a range (aka 192.168.4.50 thru 192.168.4.254) Try If mUIO_Threads(i) Is Nothing Then mUIO_Threads(i) = New System.Threading.Thread(AddressOf mUIO_DAQ(i).InitDAQ) mUIO_Threads(i).Name = mUIO_DAQ(i).UIO_IPAddr mUIO_Threads(i).IsBackground = False
0
2028
by: angshuman.agarwal | last post by:
Hi, I have a owner drawn combo box (using .Net 2.0 Framework). I have written the Nunit test for the same. I am setting the AutoCompleteSource Property (AutoCompleteSource.CustomSource) and AutoCompleteMode Property (AutoCompleteMode.Append) for the Combo at runtime and also have hidden these properties at design time. Now, when I am testing the function where I am setting AutoCompleteSource & AutoCompleteMode values, the Nunit...
0
924
by: ahpooh82 | last post by:
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
3
6053
by: =?Utf-8?B?TWFyayBDaGFubmluZw==?= | last post by:
I have a code which registers all threads with a thread dump class. At intervals this thread dump class will dump the stack trace of all threads. As calling StackTrace(threadtoDump) from a different thread other than the treadToDump the threadToDump must be suspended otherwise a ThreadStateException gets thrown. However under .NET 2.0 System.Threading.Thread.Suspend/Resume have been marked as obsolete with reference to better methods of...
2
4139
by: BruceWho | last post by:
I downloaded boost1.35.0 and built it with following command: bjam --toolset=msvc-7.1 --variant=release --threading=multi -- link=shared --with-system stage and it failed to compile, error message is: E:\software\development\boost_1_35_0\boost_1_35_0>bjam -- toolset=msvc-7.1 --variant=release --threading=multi --link=shared --
0
8863
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8739
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9157
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9088
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8052
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4502
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4762
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3207
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2602
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.