65.9K
CodeProject is changing. Read more.
Home

Changing a WinForms Control on the 'UI' Thread from another Thread

starIconstarIconstarIconstarIconstarIcon

5.00/5 (6 votes)

Mar 23, 2010

CPOL
viewsIcon

9430

this.BeginInvo...

this.BeginInvoke((ThreadStart)delegate()                        {                           

//UI change code goes here 
                                  
});
[Added by DaveyM69] This method is similar to my suggestion. The ThreadStart delegate is identical to MethodInvoker (void return - no parameters). In this situation I prefer MethodInvoker as that's what we're doing (invoking a method), not starting a thread. The use of BeginInvoke will may* allow the calling thread to continue immediately even if the 'UI thread' cannot be updated whereas Invoke will block until the 'UI thread' is updated. This may or may not be desirable! *See Luc's post in the forum below See: Control.Invoke[^] Control.BeginInvoke[^] [/Added]