Orc.NuGetExplorer.DispatchHelper.InvokeAsync C# (CSharp) Method

InvokeAsync() private static method

Executes the specified delegate asynchronously with the specified arguments on the thread that the Dispatcher was created on.
private static InvokeAsync ( this dispatcher, System.Action action ) : System.Threading.Tasks.Task
dispatcher this The dispatcher.
action System.Action The action.
return System.Threading.Tasks.Task
        private static Task InvokeAsync(this Dispatcher dispatcher, Action action)
        {
            var tcs = new TaskCompletionSource<bool>();

            var dispatcherOperation = dispatcher.BeginInvoke(new Action(() =>
            {
                try
                {
                    action();
                }
                catch (Exception ex)
                {
                    tcs.SetException(ex);
                }
            }), null);

            dispatcherOperation.Completed += (sender, e) => tcs.SetResult(true);
            dispatcherOperation.Aborted += (sender, e) => tcs.SetCanceled();

            return tcs.Task;
        }
#endif