Exemplo n.º 1
0
 /// <summary>
 /// Awaits the provided task on the UI thread. The function will be
 /// invoked on the UI thread to ensure the correct context is captured
 /// for any await statements within the task.
 /// </summary>
 /// <remarks>
 /// If called from the UI thread, the function is evaluated
 /// synchronously.
 /// </remarks>
 public override T InvokeTaskSync <T>(Func <Task <T> > func, CancellationToken cancellationToken)
 {
     return(_factory.RunAsync(async() => {
         // Convert assertions to exceptions while joining on a task
         // or the message box will deadlock.
         using (ThrowOnAssertListener.Push()) {
             await _factory.SwitchToMainThreadAsync(cancellationToken);
             return await func();
         }
     }).Join(cancellationToken));
 }
Exemplo n.º 2
0
            public static IDisposable Push()
            {
#if DEBUG
                var inner = new TraceListener[Trace.Listeners.Count];
                Trace.Listeners.CopyTo(inner, 0);
                Trace.Listeners.Clear();
                var res = new ThrowOnAssertListener(inner);
                Trace.Listeners.Add(res);
                return(res);
#else
                return(null);
#endif
            }