using System.Windows.Threading; // create Dispatcher instance Dispatcher uiThreadDispatcher = Dispatcher.CurrentDispatcher; // method to be called on background thread void UpdateUI() { uiThreadDispatcher.Invoke(() => { // update UI controls here }); }
// create new thread var thread = new Thread(() => { // do some work int result = 5 + 10; // dispatch result to UI thread Dispatcher.Invoke(() => { // update UI controls here with result }); }); // start the thread thread.Start();This example shows how to use the Dispatcher class to send a task to be executed on another thread. Package library: System.Windows.Threading namespace, part of WPF (Windows Presentation Foundation).