Click here to Skip to main content
13,588,549 members
Click here to Skip to main content
Add your own
alternative version

Tagged as


4 bookmarked
Posted 20 Jan 2013
Licenced CPOL

WPF Dispatcher.Invoke Style UI Element Update for WinForm Applications in C#

, 20 Jan 2013
Rate this:
Please Sign up or sign in to vote.
Simple code wrap for updating UI elements in cross thread applications


Developers familiar with WPF use Dispatcher.Invoke to create a delegate for updating UI elements. The style is:

// Your code here 

However Dispatcher is not available in Windows Forms. So generally Windows Form developers rely mainly upon updating the UI elements in ProgressChanged event handler of background worker. However, a simple and similar way of UI update would be nice as you may want several UI updates per progress change.

The solution might be known to many or should I say most of the prolific CodeProject developers. However I still find this question being asked in numerous forums and therefore have decided to post it here. If you already know this, great, if you do not, use it.

Using the Code

As the solution is simple, I would simply put the code. I guess nothing much is there to explain.

this.Invoke((MethodInvoker)delegate { 
            // your UI update code here. e.g. this.Close();Label1.Text="something";

One important thing that you must remember while working with updating UI elements is that it is always preferred to update the elements from UI thread. ProgressChanged is still the best place to update your UI . However it is a good practice to use this model even within ProgressChanged to ensure trouble free element update.

Points of Interest

Doing things in simpler ways is also an efficient way. Developers working extensively on cross threading models like Port programming, Web cam and Image operations, remote methods might find this technique useful. I posted as usual for beginners to save them from "Thread Horror". Your discussions, suggestions and criticism are welcome as always.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

CEO Integrated Ideas
India India
This member doesn't quite have enough reputation to be able to display their biography and homepage.
Group type: Organisation

116 members

You may also be interested in...


Comments and Discussions

PraiseThreading Pin
Reeshabh Choudhary26-Dec-15 1:44
memberReeshabh Choudhary26-Dec-15 1:44 
SuggestionThe most common approach Pin
InTRUEdeR20-Jan-13 23:04
memberInTRUEdeR20-Jan-13 23:04 
GeneralRe: The most common approach Pin
Grasshopper.iics21-Jan-13 1:03
groupGrasshopper.iics21-Jan-13 1:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web02-2016 | 2.8.180615.1 | Last Updated 21 Jan 2013
Article Copyright 2013 by Grasshopper.iics
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid