Re: cross-thread UI updating?



On Wed, 23 May 2007 23:41:22 +0200, Tim Van Wassenhove wrote:

// call this method again, but on the ui thread...
this.EndInvoke(this.BeginInvoke(new MethodInvoker(delegate()

Just a point of detail here. this.EndInvoke(this.BeginInvoke()) is
unecessarily complicated.

If you want the worker thread to block until the method invoked in the UI
thread has completed (which is what you do by calling
this.EndInvoke(this.BeingInvoke())), simply call this.Invoke() (where this
represents a Control). No need for BeginInvoke / EndInvoke here. Note that
using Control.Invoke can lead to some very subtle dead-locks if you are
sharing data protected by locks between the worker thread and the UI
thread.

If you want the worker thread to invoke a method in the UI thread but not
wait for its completion before continuing its job, simply call
this.BeginInvoke() (where this represents a Control). There is no need to
call Control.EndInvoke() (this is the only case in the .NET standard Class
Library in which the call to EndInvoke() after a BeginInvoke() is not
required).
.



Relevant Pages

  • Re: Time Critical Process in .NET
    ... In my experience Events are almost always better then polling! ... In the case of worker thread & UI thread, ... > created/taken and then released from the pool, all in a blink of an eye. ... > the delegate called via the previous BeginInvoke is finished before ...
    (microsoft.public.dotnet.general)
  • Re: Socket is freezing my datagrid
    ... > Do I have to follow any guideline to update my UI control? ... This callback is always executed within a worker thread. ... In order to safely update your datagrid from a worker thread, ... One important thing here is that the Invoke method relies on uiControl to ...
    (microsoft.public.dotnet.framework.remoting)
  • Re: Socket is freezing my datagrid
    ... >> Do I have to follow any guideline to update my UI control? ... > This callback is always executed within a worker thread. ... > marshall the call to the method that accesses your datagrid to the UI ... > // This is the method executing ...
    (microsoft.public.dotnet.framework.remoting)
  • Re: Multithreading a databound app?
    ... UI control that it is bound to. ... The grid is bound via the BindingSource to WidgetList, ... which is a llist of WidgetItem objects derived from BindingList. ... I had hoped I could populate the list on a worker thread without ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: threading questions
    ... Could the new thread just then update a control on the frmMain, as the thread was created from frmMain or is the invoke stuff still required? ... correctly without the message loop. ... and call a function in my startup form. ... I would avoid creating the frmComms form on the worker thread. ...
    (microsoft.public.dotnet.languages.vb)