Home | Articles|Namespace|Interview Questions|Tools|Jobs|Projects|Community
Asp.net Tutorials

»Dotnet Ads
»Message Boards
Message Boards
Dotnet Books

»Member Details
Register
Login
LogOut
Submit Code
Submit Jobs
Submit Projects

»Competition
Community
Winners
Prizes
Write For Us
Members

»Other Resources
Links
Dotnet Resources

C# Cross thread operation no valid solution

when trying to update controls from a thread we come across this error this small code tells how to overcome it

I have a label on a form and i want to update the label from the thread

if we do it inside the thread we get the famous error

the solution

Create a Delegate


public delegate void UpdateHandler(string str);


//// inside the thread call
this.Invoke(new UpdateHandler(changeText), "Hello World" );
//// end inside the thread



private void changeText(string str)
{
label1.text = str;
}


voila you are all set

Have a Question and dont know the answer post it below and get answers in minutes

Due to spam this feature is disabled
To get answers fast , make sure you enter a detailed subject for example: "DataGrid issues need answer" not "DataGrid"

Subject:

Catjegory Name:

Message:



© 2008 dotnetwatch.com -- Privacy policy