473,403 Members | 2,366 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

STAThrea

Hi,

I just tried to compile an 'old' .net framework 1.1 application with vs2005
- and suddenly the code throws some error in runtime:

ThreadStateException:
Current thread must set to single thread apartment (STA) mode before OLE
calls can be made. Ensure that your Main function has STAThreadAttribute
marked on it.

I tried to set the apartment state with SetApartmentState() but this failed
also ('couldn't set apartment state').

Can anyone help me out of this?

Thanks
Peter
Jul 21 '05 #1
2 1667
Peter Schmitz <Pe**********@discussions.microsoft.com> wrote:
I just tried to compile an 'old' .net framework 1.1 application with vs2005
- and suddenly the code throws some error in runtime:

ThreadStateException:
Current thread must set to single thread apartment (STA) mode before OLE
calls can be made. Ensure that your Main function has STAThreadAttribute
marked on it.

I tried to set the apartment state with SetApartmentState() but this failed
also ('couldn't set apartment state').

Can anyone help me out of this?


Usually it's easiest just to put the STAThreadAttribute on Main, but it
depends on exactly what you're doing.

What thread is the failing call running on?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #2

"Peter Schmitz" <Pe**********@discussions.microsoft.com> wrote in message
news:A5**********************************@microsof t.com...
Hi,

I just tried to compile an 'old' .net framework 1.1 application with
vs2005
- and suddenly the code throws some error in runtime:

ThreadStateException:
Current thread must set to single thread apartment (STA) mode before OLE
calls can be made. Ensure that your Main function has STAThreadAttribute
marked on it.

I tried to set the apartment state with SetApartmentState() but this
failed
also ('couldn't set apartment state').

Can anyone help me out of this?

Thanks
Peter


That's the result of a new probe in v2 that checks the thead's apartment
when calling into COM.
What error did you get when calling SetApartmentState() and on what thread
did you called this.

If it's the main thread do as Jon said, if its on a background thread, you
better call SetApartmentState before you start the thread, don't do it in
the thread procedure.

Willy.

Jul 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Lloyd Dupont | last post by:
for this config file: //-------- <?xml version="1.0" encoding="utf-8" ?> <configuration> <appSettings> <add key="Lion's Port" value="1971"/> </appSettings> </configuration> //--------
2
by: Peter Schmitz | last post by:
Hi, I just tried to compile an 'old' .net framework 1.1 application with vs2005 - and suddenly the code throws some error in runtime: ThreadStateException: Current thread must set to single...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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...
0
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,...

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.