How to

access control from different thread

Published: 15. December 2008 | Updated: 20. December 2008
License: Microsoft Public License (MS-PL)
Categories: Framework » Threading, Winforms
Tags: C# Controls Threading Winforms
Was this snippet helpful for you? YESYES / NONO
Get Analyzant!

Check your entire website from code to content in minutes with Analyzant, the free analysis suite.

Free download at analyzant.com

Code

Method for asynchronous progress change
private void SetProgress(int progress)
{
    // control have to be invoked
    if (this.progressBar1.InvokeRequired)
    {
        // invoke using delegate - call self
        this.progressBar1.Invoke((Action)delegate() { SetProgress(progress); });
    }
    else
    {
        // set progress bar value
        this.progressBar1.Value = progress;
    }
}
Send us feedback about this snippet »



Related Snippets: