Click here to Skip to main content
12,896,953 members (52,575 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


24 bookmarked
Posted 22 Mar 2010

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

, 21 Aug 2010 CPOL
Rate this:
Please Sign up or sign in to vote.
How to access a control from a different thread + good alternatives by other members!

Added: This article[^] has some interesting stuff about potential bugs with InvokeRequired - worth a read!

This comes up time and again.
Luc[^] has a great article explaining all here[^].

For those just wanting the solution...

public void WithParameterMethod(int parameter)
    if (InvokeRequired)
        Invoke(new MethodInvoker(
                // Call your method again
        // Do your thing here!

public void NoParameterMethod()
    if (InvokeRequired)
        Invoke(new MethodInvoker(
            // Call your method again
        // Do your thing here!


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


About the Author

CEO Dave Meadowcroft
United Kingdom United Kingdom
No Biography provided

You may also be interested in...


Comments and Discussions

GeneralMy vote of 5 Pin
Akram El Assas4-Apr-12 14:35
memberAkram El Assas4-Apr-12 14:35 
GeneralTo aspdotnetdev: Pin
DaveyM6923-Mar-10 16:49
mvpDaveyM6923-Mar-10 16:49 
GeneralRe: To aspdotnetdev: Pin
aspdotnetdev23-Mar-10 20:01
memberaspdotnetdev23-Mar-10 20:01 
Thanks. It took me a while (probably a year or so) before I came up with that idea. It seems blindingly obvious now, but that wasn't always the case. Though, there are advantages to each approach.

Avoids the creation of a delegate in the case that an invoke is not required (i.e., it's faster in that case).

A little cleaner. Can be used inline. In the case that an invoke is required, it takes one less function/delegate call (in the case that it is inlined).

There are some other nuances, but those are the basics. Each approach is useful in different situations. Smile | :)

GeneralRe: To aspdotnetdev: Pin
Khaniya24-Mar-10 2:50
memberKhaniya24-Mar-10 2:50 
GeneralRe: To aspdotnetdev: Pin
aspdotnetdev24-Mar-10 8:51
memberaspdotnetdev24-Mar-10 8:51 
GeneralBeginInvoke Pin
Luc Pattyn23-Mar-10 15:39
mvpLuc Pattyn23-Mar-10 15:39 
GeneralRe: BeginInvoke Pin
DaveyM6923-Mar-10 16:53
mvpDaveyM6923-Mar-10 16:53 
GeneralRe: BeginInvoke Pin
supercat924-Mar-10 4:24
membersupercat924-Mar-10 4:24 
GeneralWhy the down votes? [modified] Pin
DaveyM6923-Mar-10 0:30
mvpDaveyM6923-Mar-10 0:30 
GeneralRe: Why the down votes? Pin
HimanshuJoshi23-Mar-10 1:07
memberHimanshuJoshi23-Mar-10 1:07 
GeneralRe: Why the down votes? Pin
Sandeep Mewara23-Mar-10 2:39
memberSandeep Mewara23-Mar-10 2:39 
RantRe: Why the down votes? Pin
AWdrius23-Mar-10 22:41
memberAWdrius23-Mar-10 22:41 
GeneralRe: Why the down votes? Pin
DaveyM6923-Mar-10 23:31
mvpDaveyM6923-Mar-10 23:31 
GeneralRe: Why the down votes? Pin
AWdrius23-Mar-10 23:54
memberAWdrius23-Mar-10 23:54 
GeneralRe: Why the down votes? Pin
DaveyM6924-Mar-10 1:34
mvpDaveyM6924-Mar-10 1:34 

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 | Terms of Use | Mobile
Web02 | 2.8.170424.1 | Last Updated 21 Aug 2010
Article Copyright 2010 by DaveyM69
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid