PC Review


Reply
Thread Tools Rate Thread

Threads and GUI updating

 
 
Leif Eirik Olsen
Guest
Posts: n/a
 
      14th Jun 2005
Hi,

I have a main form frmMain, frmMain creates an instance of a class MyThread.
MyThread creates a thread and countiously reads a comport for some string
data.
When a certain string is recieved MyThread fires an event OnDataRecieved.
frmMain has an eventhandeler implemented (DataRecieved) for the
MyThread.OnDataRecieved event.

So finally my question
Is it safe to update textbox and label values from within
frmMain.DataRecieved ?

Any help or hints greatly appriciated.

regards,
Leo


 
Reply With Quote
 
 
 
 
Guest
Posts: n/a
 
      14th Jun 2005
> So finally my question
> Is it safe to update textbox and label values from within
> frmMain.DataRecieved ?


Absolutely not. It's not safe in the CF or full framework. Use
Control.Invoke to marshal a call back to the primary UI thread and update
from there.

-Chris



 
Reply With Quote
 
Leif Eirik Olsen
Guest
Posts: n/a
 
      14th Jun 2005
"<ctacke/>" <ctacke_AT_OpenNETCF_com> skrev i melding
news:(E-Mail Removed)...
>
> Absolutely not. It's not safe in the CF or full framework. Use
> Control.Invoke to marshal a call back to the primary UI thread and update
> from there.


Ok, I see

I understand I need to do something like this from MyThread :

frmMain.Invoke(new Eventhandler(aGuiUpdateMethodeInfrmMain);
right?

If this is correct is there a more 'dynamic' way to do the call. I do not
like the idea tha MyThread needs to know both frmMain and
aGuiUpdateMethodeInfrmMain.

Could mabe MyThread take a inparameter ('methode to invkoke'?) when
constructed ? Tried this, but with no luck so far.

regards,
Leo


 
Reply With Quote
 
Graham McKechnie
Guest
Posts: n/a
 
      15th Jun 2005
Leo,

You may want to read this.

http://msdn.microsoft.com/mobility/w...adingandui.asp

Graham

"Leif Eirik Olsen" <leif-eirik.olsen@_REMOVE_plugging.com> wrote in message
news:%(E-Mail Removed)...
> Hi,
>
> I have a main form frmMain, frmMain creates an instance of a class
> MyThread.
> MyThread creates a thread and countiously reads a comport for some string
> data.
> When a certain string is recieved MyThread fires an event OnDataRecieved.
> frmMain has an eventhandeler implemented (DataRecieved) for the
> MyThread.OnDataRecieved event.
>
> So finally my question
> Is it safe to update textbox and label values from within
> frmMain.DataRecieved ?
>
> Any help or hints greatly appriciated.
>
> regards,
> Leo
>
>



 
Reply With Quote
 
Leif Eirik Olsen
Guest
Posts: n/a
 
      16th Jun 2005
"Graham McKechnie" <(E-Mail Removed)> skrev i melding
news:%(E-Mail Removed)...
> Leo,
>
> You may want to read this.
>
>

http://msdn.microsoft.com/mobility/w...adingandui.asp
>
> Graham


Thanks alot, that looks interesting.

regards,
Leo


 
Reply With Quote
 
 
 
Reply

Thread Tools
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problems with threads updating listbox Claire Microsoft C# .NET 0 16th Aug 2007 05:24 PM
multiple threads updating same log file cj Microsoft VB .NET 6 17th Feb 2006 03:13 AM
Threads Question - updating UI Flashster Microsoft VB .NET 2 19th Jan 2006 10:19 PM
Is updating Excel cells from multiple threads a bad idea? Hans Merkl Microsoft Excel Programming 5 8th Dec 2005 09:29 AM
Updating GUI controls from threads Curious Microsoft C# .NET 10 11th Oct 2005 11:51 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:00 PM.