WinForms
private delegate void UpdateUiTextDelegate(Control control, string text);
private void UpdateUiText(Control control, string text)
{
if(InvokeRequired)
{
Invoke(new UpdateUiTextDelegate(UpdateUiText), new object[] {control, text});
return;
}
control.Text = text;
}
WPF
private void UpdateUiText(Control control, string text)
{
if(!Dispatcher.CheckAccess())
{
Dispatcher.Invoke(DispatcherPriority.Send, new UpdateUiTextDelegate(UpdateUiText), control, text);
return;
}
control.Text = text;
}