This is the extension method:
public static void ThreadSafeCall(this Control control, MethodInvoker method)
{
if (control.InvokeRequired)
{
try
{
control.Invoke(method);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
else
{
method.Invoke();
}
}
Below is the use of it:
txtOutput.ThreadSafeCall((MethodInvoker)delegate { txtOutput.Text = "Updated"; });