Re: Beginner's Question about Threading

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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
> >
>
>
>
.



Relevant Pages

  • RE: Beginners Question about Threading
    ... directly but must use 'Invoke' or 'BeginInvoke'. ... Generally the WinForms app works under ... >> In addition to the main desktop app window I also have a Notification form ... >> user about what is happening during the Data Transfer process. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: PING: Miche: 7.6 Earthquake!
    ... Pan - and that even has an option to 'hide quoted text' when reading ... posts ... how do you invoke it? ... i was trying to invoke it in the reply composition window, ...
    (rec.food.cooking)
  • Re: Invoke vs .... (for thread communication with UI controls)
    ... >while another is reading it. ... I wouldn't recommend this approach. ... The 'invoke' mechanism? ... You'd think this would be a commonly encountered problem, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Place Cursor At The Top
    ... to invoke a lot of emotions. ... That means I snip out what's not needed and I try to make sure no on has to scroll to begin reading my reply. ... Entourage Help Blog ...
    (microsoft.public.mac.office.entourage)
  • Re: newb: How to call one modue from other
    ... Yes, because the original script author didn't want to call a function inside that module, instead, he wanted to invoke the module as a child program. ... Reading the Python Tutorial helps a lot. ...
    (comp.lang.python)