Click here to Skip to main content
11,431,829 members (62,688 online)
Click here to Skip to main content

Tagged as

Debugging Cross thread exceptions

, 5 Aug 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
Recently, I was stuck with following error,
"Cross-thread operation not valid: Control 'label1' accessed from a thread other than the thread it was created on."

The error has been resolved using below code. I am posting it here because it may help someone.
public void SetStatus(string msg)
    if (label1.InvokeRequired)
        label1.Invoke(new MethodInvoker(delegate
            label1.Text = msg;
        label1.Text = msg;

Credits goes to 'IAbstract'. Link :Click here


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


About the Author

Syed Shabeer
Software Developer
India India
A Software programmer. Works on ASP.NET, MVC, VB.NET, C#, .NET Compact framework, SSIS, SQL Server, PHP and its frameworks. Other than that likes to play games in PC.
Follow on   Twitter

Comments and Discussions

GeneralReason for my vote of 5 While it may not be debugging, I am ... Pin
Member 822542223-Sep-11 3:17
memberMember 822542223-Sep-11 3:17 
GeneralReason for my vote of 1 sorry for downvoting, but on CP ther... Pin
johannesnestler11-Aug-11 4:17
memberjohannesnestler11-Aug-11 4:17 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.150428.2 | Last Updated 5 Aug 2011
Article Copyright 2011 by Syed Shabeer
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid