Serban Cosmin59 reputationPosted Jun 8, 2010, 4:41 AM EDT
✓ Accepted answer0
Hy, For every user interface element that you want to modify from a separate thread, you must use the Invoke method, otherwise you will get the error you mention. You must first create a delegate and a method that modifies the user interface, like this: delegate void ModifyText( string msg ); private void ModifyLabelText( string msg ) { lblinc.Text = msg; } // in the thread method : ModifyText modifyText = new ModifyText( ModifyLabelText ); this.Invoke( modifyText, new object[ ] { "The incremented value is .... " } );
This should do the trick.
You can create something similar for modifying the button's state.
Serban Cosmin59 reputationPosted Jun 8, 2010, 4:41 AM EDT
For every user interface element that you want to modify from a separate thread, you must use the Invoke method, otherwise you will get the error you mention. You must first create a delegate and a method that modifies the user interface, like this:
delegate void ModifyText( string msg );
private void ModifyLabelText( string msg )
{
lblinc.Text = msg;
}
// in the thread method :
ModifyText modifyText = new ModifyText( ModifyLabelText );
this.Invoke( modifyText, new object[ ] { "The incremented value is .... " } );
This should do the trick.
You can create something similar for modifying the button's state.