Since this post, .NET 4 has arrived. The <Control>.Dispatcher.CheckAccess() is now made available in Intellisense (in VS). In addition, an easier code construct than the initial version, is the below (note: ‘btnSplit’ is a Button in this case):
private void HandleUIButtons()
//if here - we are on a different non-UI thread
btnSplit.IsEnabled = true; //this is ultimately run on the UI-thread
Doing some multithreading coding in WPF – I again today stumbled upon the missing InvokeRequired functionality known from WinForms coding. The InvokeRequired bool property on a control that is used when doing mulithreaded WinForms coding, has been replaced by the Dispatcher.CheckAccess() method call in WPF.
Be aware that the old property (InvokeRequired) returned true if the calling thread was different from the owning thread; whereas the Dispatcher.CheckAccess() methodcall returns true if the calling thread is the SAME as the owning thread. In other words – the response is reversed so to speak.
Note: The Dispathcer.CheckAccess() method does NOT show up in Visual Studio due to a System.ComponentModel.EditorBrowsableState.Never method attribute in the source code from Microsofts hand!
//check whether the calling thread is the thread owning the txtDBConn control
var popAct = new Action(PopulatePage);
txtDBConn.Dispatcher.BeginInvoke(popAct, System.Windows.Threading.DispatcherPriority.DataBind, null);
this.txtDBConn.Text = ConfigurationManager.ConnectionStrings[Constants.Database.DB_CONN].ConnectionString;