Re: Beginner's Question about Threading
- From: Robert W. <RobertW@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 24 Aug 2005 13:08:02 -0700
Ignacio,
Does the rest of the code look okay to you?
In my reading, it was generally recommended to use BeginInvoke to make it
asynchronous whereas Invoke would block until the message was posted. Or is
this not the case?
--
Robert W.
Vancouver, BC
www.mwtech.com
"Ignacio Machin ( .NET/ C# MVP )" wrote:
> Hi,
>
> You should not need to call DoEvents() , nor need to use BeginInvoke , a
> simple Invoke will do in this case.
>
> Cheers,
>
> --
> Ignacio Machin,
> ignacio.machin AT dot.state.fl.us
> Florida Department Of Transportation
>
>
>
> "Robert W." <RobertW@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
> news:E7949E98-0B46-408B-9279-43B9460EEF7E@xxxxxxxxxxxxxxxx
> > I'm creating a WinForms app that will act as a companion (think
> > administrator
> > functionality) to a Pocket PC app. Generally the WinForms app works under
> > just the UI thread. But if a Pocket PC connects to the desktop via
> > ActiveSync then a separate thread is spawned.
> >
> > In addition to the main desktop app window I also have a Notification form
> > that appears in the lower right of the screen and provides feedback to the
> > user about what is happening during the Data Transfer process. At first I
> > instantiated this small form from the Data Transfer thread but then read
> > several articles and decided to also instantiate it from the UI thread.
> >
> > I was having all kinds of problems sending update messages from the Data
> > Transfer thread to the Notification form but did some more reading and
> > realized that I was breaking the primary threading rule about updating a
> > control only from the thread where it was created. From my reading I
> > created
> > methods inside the Notification form class that look like this:
> >
> >
> > private delegate void ShowStatusDelegate(string text);
> > public void ShowStatus(string text)
> > {
> > if (this.InvokeRequired)
> > {
> > this.BeginInvoke(new ShowStatusDelegate(ShowStatus), new object[]
> > {text});
> > return;
> > }
> >
> > // Only reaches here when on UI thread
> > labelStatus.Text = text;
> > Application.DoEvents();
> > }
> >
> >
> >
> > I have two immediate questions:
> >
> > 1. Does the code in this method look correct and "solid" ?
> >
> > 2. Do I need the "Application.DoEvents()" line or is it unnecessary?
> >
> > --
> > Robert W.
> > Vancouver, BC
> > www.mwtech.com
> >
>
>
>
.
- Follow-Ups:
- Re: Beginner's Question about Threading
- From: Brian Gideon
- Re: Beginner's Question about Threading
- References:
- Beginner's Question about Threading
- From: Robert W.
- Re: Beginner's Question about Threading
- From: Ignacio Machin \( .NET/ C# MVP \)
- Beginner's Question about Threading
- Prev by Date: progress bar
- Next by Date: RE: Beginner's Question about Threading
- Previous by thread: Re: Beginner's Question about Threading
- Next by thread: Re: Beginner's Question about Threading
- Index(es):
Relevant Pages
|