GIDForums  

Go Back   GIDForums > Computer Programming Forums > .NET Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 22-Jan-2009, 04:14
roidrage666 roidrage666 is offline
New Member
 
Join Date: Jan 2009
Posts: 7
roidrage666 is on a distinguished road

Control ‘X′ accessed from a thread other than the thread it was created on


I try to access some controls from the DataReceived event of a serial port..

I get :
Control ‘X′ accessed from a thread other than the thread it was created on

I googled for a while, and I found this answer to the cross-thread probl.

C-SHARP / C# Code:
private void Form1_Load(object sender, EventArgs e)
{
if(InvokeRequired)
{
this.Invoke(new EventHandler(Form1_Load), new object[]
{sender, e});
return;
}
//Your code here...
}

but it doesn;t work (I guess it has to do with the 'object' thing since DataReceived uses 'System::IO:orts::SerialDataReceivedEventArgs' instead of EventArgs)
Last edited by LuciWiz : 22-Jan-2009 at 06:47. Reason: Please insert your C# code between [c#] & [/c#] tags
  #2  
Old 27-Jan-2009, 01:53
roidrage666 roidrage666 is offline
New Member
 
Join Date: Jan 2009
Posts: 7
roidrage666 is on a distinguished road

Re: Control ‘X′ accessed from a thread other than the thread it was created on


None?
  #3  
Old 27-Jan-2009, 08:38
fakepoo fakepoo is offline
Regular Member
 
Join Date: Oct 2007
Posts: 757
fakepoo is a jewel in the roughfakepoo is a jewel in the roughfakepoo is a jewel in the rough

Re: Control ‘X′ accessed from a thread other than the thread it was created on


Here is how you can do it:
C-SHARP / C# Code:
private delegate void DoSomethingToTheControlDelegate( string argument );
private void DoSomethingToTheControl( string argument )
{
  if (this.InvokeRequired)
  {
    this.Invoke(new DoSomethingToTheControlDelegate(argument), new object[] { argument });
    return;
  }  
  
  // Put the code here to do something to the control
  //........
}
 
 

Recent GIDBlogVista ?Widgets? on Windows XP by LocalTech

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to control dying of a thread in MFC application?? buffet MS Visual C++ / MFC Forum 1 27-Apr-2007 18:29
Thread synchronization Assignment help!! rossi143 C Programming Language 1 25-Mar-2007 21:10
Thread itch C++ Forum 7 10-May-2006 16:10
changing colour of individual items of control created through CListCtrl Sadia MS Visual C++ / MFC Forum 0 01-Jul-2005 09:09
Help! Some basal questions about MFC xutingnjupt MS Visual C++ / MFC Forum 1 05-Dec-2004 04:38

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 02:18.


vBulletin, Copyright © 2000 - 2010, Jelsoft Enterprises Ltd.