473,386 Members | 1,804 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,386 software developers and data experts.

Clipboard and STAThreadAttribute

I got the error when I execute the following line of code:

Clipboard.SetDataObject(mGrid.Clip);

The error is:

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

FYI, I started a separate thread and defined a "Run" method and that's
where I got the error. I don't have to do it this way. However, just
curious why this doesn't work. I'm dying to know why.

Oct 10 '07 #1
2 2490
>FYI, I started a separate thread and defined a "Run" method and that's
>where I got the error. I don't have to do it this way. However, just
curious why this doesn't work. I'm dying to know why.
You have to set the thread's ApartmentState property to STA when you
start it to use objects like the clipboard.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Oct 11 '07 #2

Have you find any solution yet?
I have [System.STAThreadAttribute()] marked before my main(). I tried
to delete all dll and rebuilt my project. I am still getting the same
error message while trying to Clipboard.Clear().

Thanks in advance!
*** Sent via Developersdex http://www.developersdex.com ***
Dec 13 '07 #3

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

Similar topics

4
by: Wayne Wengert | last post by:
I have an aspx page on which I am trying to copy the contents of a textbox to the client clipboard when the users clicks a button. The button code is as follows:...
2
by: Roy Gunnarsson | last post by:
Hello all, I have a VERY simple windows application that decrypts data files we receive from a partner. The decryption is handled by a COM component our partner provided us with (thus we have no...
9
by: Tim Frawley | last post by:
I have converted a VB6 application to VB.NET. The old application made extensive use of the Clipboard for copying an Image Name so that it could be pasted into the image capture app when the user...
3
by: SAL | last post by:
I have the following VB.net Class/Function that I call from an ASP.net page: Public Class MyTestClass Public Function embedHyperlink(ByVal fileID As Integer, ByVal fileName As String) As String...
0
by: renfes | last post by:
Hey everyone. I have a program that watches a .txt log file from a chat client or a game and based on each line, triggers events. One thing I am trying to do is send the contents of a text file to...
1
by: Sefner | last post by:
Hey everyone. I have a program that watches a .txt log file from a chat client or a game and based on each line, triggers events. One thing I am trying to do is send the contents of a text file to...
5
by: Sin Jeong-hun | last post by:
class Engine { Thread Worker; public event ... EngineMessage; public void Start() { Worker=new Thread(new ThreadStart(Run)); Worker.Start(); } private Run()
2
by: asmapanjabi | last post by:
am using C#.net 1.1 while using clipboard m geeting this exception System.Threading.ThreadStateException: Current thread must be set to single thread apartment (STA) mode before OLE calls can be...
5
by: Max2006 | last post by:
Hi, No matter what I have in clipboard Clipboard.GetDataObject(); returns null. I suspect it might be a problem with Vista or VS2008 IDE debug mode problem? Is there any way to track why the...
1
by: advsoft | last post by:
I'm trying to copy to the clipboard a text that is read from the serial port, but when try to use: Clipboard.SetText(MyTexo,MyText Format) give me the follow error: Current thread must be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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,...

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.