SafeInvoke

public delegate void InvokeHandler();
public static void SafeInvoke(this System.Windows.Forms.Control control, InvokeHandler handler)
{
	if (control.InvokeRequired) control.Invoke(handler);
	else handler();
}
Example:
//(from an event handler or public method on a form)

this.SafeInvoke(() =>
{
	textBox1.Text = "Hello, World!";
});

Description

Properly invokes an action if it is required. Best way to handle events and threaded operations on a form.

Details

Double click on the code to select all.

 

;