senpost
4/20/2011 - 3:09 PM

Updating UI controls from background thread/other than UI thread

Updating UI controls from background thread/other than UI thread

//WinForms Control.Invoke
public Object Invoke(
	Delegate method
)

//WPF Dispatcher.Invoke 
public Object Invoke(
	DispatcherPriority priority,
	TimeSpan timeout,
	Delegate method,
	Object arg,
	params Object[] args
)
//In WPF, only the thread that created a DispatcherObject may access that object. 
//For example, a background thread that is spun off from the main UI thread cannot update the contents of a Button that was created on the UI thread. 
//In order for the background thread to access the Content property of the Button, the background thread must delegate the work to the Dispatcher associated with the UI thread.