473,804 Members | 2,999 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

(Urgent)Regardi ng : STAThreadAttrib ute

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
STAThreadAttrib ute 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.Threa d.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 7910
100
Hi Chandrakant,
If you use VB your application's main thread runs in STA mode.
However, if you get *1* from Threading.Threa d.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
"Chandrakan t Shinde" <sh******@hotma il.com> wrote in message
news:uR******** ******@TK2MSFTN GP09.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
STAThreadAttrib ute 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.Threa d.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******** ******@tk2msftn gp13.phx.gbl...
Hi Chandrakant,
If you use VB your application's main thread runs in STA mode.
However, if you get *1* from Threading.Threa d.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
"Chandrakan t Shinde" <sh******@hotma il.com> wrote in message
news:uR******** ******@TK2MSFTN GP09.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
STAThreadAttrib ute 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.Threa d.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
1257
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. But...Is there any way to change the images without refreshing the page using AdRotator or by using any other controls?
3
1419
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 can get its own data.Is this possible in webservice?coz i think it seems to lose the data each time i call the webservice Plz help me in this matter.Its urgent!!! *-----------------------*
8
5269
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 developing a web-based application, one part of which involves allowing the user the ability to page through transaction "history" information. The _summary_ history table will have the following fields: ServiceName, Date, User-Ref1, User-Ref2,...
1
1161
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 can get its own data.Is this possible in webservice?coz i think it seems to lose the data each time i call the webservice Plz help me in this matter.Its urgent!!! *-----------------------*
16
2972
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: http://www.mywebsite.org/WebResource.axd?d=5WvLfhnJp5Lc8WhQSD4gdA2&t=632614619884218750 -------------------------------------------------------------------------------- System.Security.Cryptography.CryptographicException: Padding is invalid and cannot be removed. at...
4
1401
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 way attribute is set as i don't want any return value from that method. What i observered is when my window application start calling web method asynchronoysly
5
2309
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 ex... in the code i am getting color=rs("color")according to the condtion if(shirt=name) if i get red, blue as result the i want these two colors to be in selectbox.. if its three colors means i want those three colors to get displayed in...
10
1096
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 Dhananjay
0
850
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,
0
9704
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
9572
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,...
0
10319
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10303
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
10070
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
9132
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
6845
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5508
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...
1
4282
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

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.