The DispatcherHelper class enables easy interaction with CoreDispatcher, mainly in the case of executing a block of code on the UI thread from a non-UI thread.

What is included in the helper? - Extension method with overloads for CoreDispatcher class. - Extension method with overloads for CoreApplicationView (for multi window applications). - Static helper methods for executing a specific function on the UI thread of the current application's main window.


    // Executing from a non-UI thread with helper method
     int returnedFromUIThread = await DispatcherHelper.ExecuteOnUIThreadAsync<int>(() =>
         // Code to execute on main window's UI thread
         NormalTextBlock.Text = "Updated from a random thread!";
         return 1;

     // returnedFromUIThread now is 1, execution can go on from the non-UI thread

     // Or update it manually via the Extension method for CoreDispatcher
     returnedFromUIThread = await CoreApplication.MainView.Dispatcher.AwaitableRunAsync<int>( () =>
         NormalTextBlock.Text = "Updated from a random thread with extension method!";
         return 1;

Requirements (Windows 10 Device Family)

Device family Universal, 10.0.10586.0 or higher
Namespace Microsoft.Toolkit.Uwp