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;
}));
else
label1.Text = msg;
}
Credits goes to 'IAbstract'. Link :
Click here
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.