473,938 Members | 2,304 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Clipboard and STAThreadAttrib ute

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

Clipboard.SetDa taObject(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
STAThreadAttrib ute 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 2519
>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.STAThrea dAttribute()] 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
9202
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: ===================================== Private Sub btnCopyToClipboard_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCopyToClipboard.Click Clipboard.SetDataObject(txtHidden.Text) End Sub
2
5270
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 control over its functionality). That, however, works fine. To make it a little easier for our end users, I wanted to include a feature that places the path and name of the decrypted file on the clipboard. I was going to do this by using...
9
5967
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 scans the image. My applications run as compiled assemblies from our Intranet server and I have setup a Main sub routine in the application with the following line: <STAThread()> Public Sub Main() Note: There is no timer in this application.
3
3734
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 'Create a New Instance of the HyperLink Control Dim createHyperLink As New System.Web.UI.WebControls.HyperLink 'Create an Instance of the ClipBoard Object
0
2998
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 the clipboard, then paste it to the program... Here is the code I am using... namespace Project1 { public partial class Form1 : Form {
1
4558
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 the clipboard, then paste it to the program... Here is the code I am using... namespace Project1 { public partial class Form1 : Form {
5
4195
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
2135
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 made. Ensure that your Main function has STAThreadAttribute marked on it. at System.Windows.Forms.Clipboard.GetDataObject()
5
9798
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 following statement is always null? IDataObject iData = Clipboard.GetDataObject(); Thank you,
1
2694
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 set to single thread apartment (STA) mode before OLE calls can be made. Ensure that your Main function has STAThreadAttribute marked on it. Im using VB.Net 2008 and is a single form program. What could be wrong.
0
9963
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
11522
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
11104
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...
0
10655
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
9854
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
7380
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
6292
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4903
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
2
4444
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.