ExtensionMethod.NET Home of 876 C#, Visual Basic, F# and Javascript extension methods


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


public delegate void InvokeHandler();
public static void SafeInvoke(this System.Windows.Forms.Control control, InvokeHandler handler)
	if (control.InvokeRequired) control.Invoke(handler);
	else handler();


//(from an event handler or public method on a form)

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

Author: David Harris

Submitted on: 21 aug. 2010

Language: C#

Type: System.Control

Views: 15992