AppEventsSample.Helpers.DispatcherHelper.SafeDispatch C# (CSharp) Method

SafeDispatch() public static method

Executes an action on the UI thread. If this method is called from the UI thread, the action is executed immendiately. If the method is called from another thread, the action will be enqueued on the UI thread's dispatcher and executed asynchronously.

For additional operations on the UI thread, you can get a reference to the UI thread's dispatcher thanks to the property UIDispatcher

.
public static SafeDispatch ( System.Action action ) : void
action System.Action The action that will be executed on the UI /// thread.
return void
        public static void SafeDispatch(Action action)
        {
            if (UIDispatcher.CheckAccess())
            {
                action();
            }
            else
            {
                UIDispatcher.BeginInvoke(action);
            }
        }