473,466 Members | 1,453 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

(Urgent)Regarding : STAThreadAttribute

Hi there,
I want to copy a Image to the clipboard. When i try to do so following
exception occurs :
"The 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"
Following are the points i want to say :
1. Which is the main method in windows forms ? When i tried to assign
<STAThread()> attribute to Public sub New () it gave me error.
2. I tried adding module contaning public sub main() assigning <STAThread()>
attribute, but above exception continues.
3. When i am checking the Threading.Thread.CurrentThread.ApartmentState
property in the function where exception is there , it is showing me the
value 1.
4. In my whole application I have never used Threads manually.But it does
contain many events.
Application i am working on is based on Client Server Architecure and
the code which gives exception is written on Server Side.This code gets
executed when request is received from the client.

Plz give me suggestions, its very URGENT.
Thanks in advance.

Chandrakant Shinde
Nov 20 '05 #1
2 7892
100
Hi Chandrakant,
If you use VB your application's main thread runs in STA mode.
However, if you get *1* from Threading.Thread.CurrentThread.ApartmentState
that means MTA mode.
If you copy the immage in the clipboard as a response of an event the
corresponding event handler may be executed in separate thread from the
thread pool. Make sure you don't use somewhere BeginInvoke method.

If you don't have control on how the events are fired what you can do is to
call Control.Invoke to switch back to the main thread and then copy the
image.
HTH
B\rgds
100
"Chandrakant Shinde" <sh******@hotmail.com> wrote in message
news:uR**************@TK2MSFTNGP09.phx.gbl...
Hi there,
I want to copy a Image to the clipboard. When i try to do so following
exception occurs :
"The 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"
Following are the points i want to say :
1. Which is the main method in windows forms ? When i tried to assign
<STAThread()> attribute to Public sub New () it gave me error.
2. I tried adding module contaning public sub main() assigning <STAThread()> attribute, but above exception continues.
3. When i am checking the Threading.Thread.CurrentThread.ApartmentState
property in the function where exception is there , it is showing me the
value 1.
4. In my whole application I have never used Threads manually.But it does
contain many events.
Application i am working on is based on Client Server Architecure and
the code which gives exception is written on Server Side.This code gets
executed when request is received from the client.

Plz give me suggestions, its very URGENT.
Thanks in advance.

Chandrakant Shinde

Nov 20 '05 #2
Thanks 100,
Your Idea worked !!!!!

Chandrakant Shinde
----------------------------------------------------------------

"100" <10*@100.com> wrote in message
news:Or**************@tk2msftngp13.phx.gbl...
Hi Chandrakant,
If you use VB your application's main thread runs in STA mode.
However, if you get *1* from Threading.Thread.CurrentThread.ApartmentState
that means MTA mode.
If you copy the immage in the clipboard as a response of an event the
corresponding event handler may be executed in separate thread from the
thread pool. Make sure you don't use somewhere BeginInvoke method.

If you don't have control on how the events are fired what you can do is to call Control.Invoke to switch back to the main thread and then copy the
image.
HTH
B\rgds
100
"Chandrakant Shinde" <sh******@hotmail.com> wrote in message
news:uR**************@TK2MSFTNGP09.phx.gbl...
Hi there,
I want to copy a Image to the clipboard. When i try to do so following
exception occurs :
"The 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"
Following are the points i want to say :
1. Which is the main method in windows forms ? When i tried to assign
<STAThread()> attribute to Public sub New () it gave me error.
2. I tried adding module contaning public sub main() assigning

<STAThread()>
attribute, but above exception continues.
3. When i am checking the Threading.Thread.CurrentThread.ApartmentState
property in the function where exception is there , it is showing me the value 1.
4. In my whole application I have never used Threads manually.But it does contain many events.
Application i am working on is based on Client Server Architecure and the code which gives exception is written on Server Side.This code gets
executed when request is received from the client.

Plz give me suggestions, its very URGENT.
Thanks in advance.

Chandrakant Shinde


Nov 20 '05 #3

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

Similar topics

0
by: Kiran R | last post by:
Hi, Is there any way to show different advertisements(images) in a certain interval of time using AdRotator. I am able to display different images when the page get refreshed using AdRotator....
3
by: sunnyz | last post by:
hi I wanted to know whether we can store something in Session objects in webservice.My windows application calls the webservice and i want the data to be stored in Session object so that each user...
8
by: Mike | last post by:
Hello, I have a few rather urgent questions that I hope someone can help with (I need to figure this out prior to a meeting tomorrow.) First, a bit of background: The company I work for is...
1
by: sunnyz | last post by:
hi I wanted to know whether we can store something in Session objects in webservice.My windows application calls the webservice and i want the data to be stored in Session object so that each user...
16
by: | last post by:
Hi all, I have a website running on beta 2.0 on server 2003 web sp1 and I keep getting the following error:- Error In:...
4
by: archana | last post by:
Hi all, I am having one confusion regarding invoking web method of web service asychronously through windows applicaiton. What i am doing is i am having one long runing web method whose one...
5
by: meenu_susi | last post by:
doubt regarding select box....urgent in the below code i am getting data from database..according to the condition.. i want the available data in database to get displayed in selectbox.. for...
10
by: Dhananjay | last post by:
hello everyone Do you have any information how to generate a tool using .net which is used to translate the web page contents to html format. Plz reply me asap Thanks in advance ...
0
by: gsreenathreddy | last post by:
Hi! In our project we would like to use Tiles, I would like to know that using layouts whether entire page is going to be loaded for any request or only a part is loaded. Thank you,
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
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
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

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.