Last post Mar 12, 2010 03:04 AM by jojee82
Jun 29, 2007 03:53 PM|pulkitzery|LINK
I am getting this error when my application tries to show a form:
By googling the exception message I found that I have to set the thread apartment to STA, so I added this code into my form_load event:
I did some further research and found that I need to add <STAThread> to the main function. I created a new module and defined my main function and set the attribute to STAThread…
But that did not help either and I got the first error message again.
I have no idea why is this happning. BTW this happens only if I use .net Remoting library to communicate in network.
I need to solve it ASAP. Can any one please help me out here. Thanks very much in advance for your help and time.
Jul 02, 2007 09:28 PM|Rex Lin - MSFT|LINK
HI, Pulkit Zery:
What is the purpose of your application? Are you attempting to start a form (with DragDrop enabled) or
using the clip board within a
Jul 03, 2007 11:42 AM|pulkitzery|LINK
Thanks for your attention, i was able to figure it out by myself. I need to set the
SetApartmentState of my thread to STA and it worked like charm. Thanks very much.
BTW I had another question that, how can I use remoting without adding reference of the remoting class into my client application? Is it even possible?
Jul 03, 2007 10:11 PM|Rex Lin - MSFT|LINK
HI, Pulkit Zery :
Congratulations for solving it by yourself with the great solution!
Secondly, In this thread, we are mainly discussing about Thread STA Attribute, as indicated by the first post and the title.
Since your new question is not directly related to the original issue, it would be best if you open up a new thread for the new question. In this way, our discussion here will not deviate too much from the original issue. This will make answer searching in
the forum easier and be beneficial to other community members as well.
Thank you for your understanding.
Aug 02, 2007 06:07 PMfirstname.lastname@example.org|LINK
Can anybody help me with the following error please?
The error is: ActiveX control 'ca8a9780-280d-11cf-a24d-444553540000' cannot be instantiated because the current thread is not in a single-threaded apartment.
My VB2005 application uses an AcrobatReader ActiveX control for automating printing of PDFs.
I'm also using a FileSystemWatcher that reports new files that will be printed with the Acrobat Reader.
There is a lot of stuff to find about this error, but unfortunately I am a newby and thus not understand how to solve.
(Its all about the Apartmenstate (STA) of my application but I do not find where I can change that)
Can anybody guide me to the correct place and correct syntax to do this please?
Are does anybody has another idea to fix this?
Thanks in advance,
Aug 03, 2007 10:12 AM|pulkitzery|LINK
I had the same issue in past, and I was able to figure it out by myself. Here is the code I used to fix it:
'This is the thread that does all the work
Dim oThread As Threading.Thread
'Kill any previously running thread...
If Not Me.oThread Is Nothing Then
Me.oThread = Nothing
‘Define new instance of our thread
Me.oThread = New Threading.Thread(AddressOf Me.RunEncoder)
'Change the ApartmentState to STA (Single Thread Apartment)
'Start the thread...
What you really should do is to fist check if this is an issue of having threadstate not STA. You can check that by debugging into the code or put a message box in your thread
prompting you the thread state. If that’s the case then the above code should fix it.
Let me know…
Aug 14, 2007 02:22 AMemail@example.com|LINK
sorry for my late answer, just back from holliday.
My problem is for sure a STA/MTA problem.
I have checked it and after the FileSystemWatcher has thrown a 'New File' message, my application changes from STA to MTA.
I have tried your code without success.
However I have rewritten my code without the FileSystemWatcher.
Now I made an infinte loop that checks my folders for new files.
In this way everything goes just fine.
I know, this is not the good way but its the best I can do today.....
If you have other suggestions...
Aug 19, 2007 06:13 AM|mbruyns|LINK
please help? i'm getting the error about the thread not being in STA as per your post. i'm working in vb and asp, and the error is coming up as i try to create a new webbrowser object in a class thats in my business layor (in a sep project in the same
i tried adding that code that you posted, but (after first needing to remove all the "me" keywords) it says the "RunEncoder" does not exist. do i need to create this method?
i also tried using "Thread.CurrentThread.SetApartmentState(ApartmentState.STA)" but also got the error "Failed to set the specified COM apartment state"
Please help? I'm pretty much a noob at all of this! :o(
Mar 12, 2010 03:04 AM|jojee82|LINK
Have a look at this one...
(Go to page bottom)