Method 1: update a single control:
Public Delegate Void Controltextmethod (Control, String Text );
Private Void Setcontroltext (Control, String Text)
{
If ( This . Invokerequired)
{
Controltextmethod = New Controltextmethod (setcontroltext );
This . Invoke (controltextmethod, New Object [] {Control, text });
}
Else
{
Control. Text = text;
}
}
You can directly call the setcontroltext method to update the text of the control.
Method 2: Use uithread ":
Public Void Uithread (methodinvoker method)
{
If ( This . Invokerequired)
{
This . Invoke (method );
}
Else
{
Method. Invoke ();
}
}
Public VoidUpdateui ()
{
This. Uithread (Delegate
{
This. Label1.text ="Msg1";
This. Label2.text ="Msg2";
});
}
Call this when you want to update the interface: This. uithread (delegate {This. label1.text = "msg1 ";...});.
Method 3: Update multiple controls in one method:
Public Void Updateui ()
{
If ( This . Invokerequired)
{
This . Invoke ( New Methodinvoker ( Delegate {Updateui ();}));
}
Else
{
This . Label. Text = " Msg1 " ;
This . Labe2.text = " Msg2 " ;
}
}