Exemple #1
0
 internal static void ThrowAsync(Exception exception, SynchronizationContext targetContext)
 {
     if (targetContext != null)
     {
         try
         {
             targetContext.Post(delegate(object state)
             {
                 throw TaskAwaiter.PrepareExceptionForRethrow((Exception)state);
             }, exception);
             return;
         }
         catch (Exception ex)
         {
             exception = new AggregateException(new Exception[]
             {
                 exception,
                 ex
             });
         }
     }
     ThreadPool.QueueUserWorkItem(delegate(object state)
     {
         throw TaskAwaiter.PrepareExceptionForRethrow((Exception)state);
     }, exception);
 }
        private static void ThrowForNonSuccess(Task task)
        {
            switch (task.Status)
            {
            case TaskStatus.Canceled:
                throw new TaskCanceledException(task);

            case TaskStatus.Faulted:
                throw TaskAwaiter.PrepareExceptionForRethrow(task.Exception.InnerException);

            default:
                throw new InvalidOperationException("The task has not yet completed.");
            }
        }
Exemple #3
0
 /// <summary>
 /// Throws the exception on the ThreadPool.
 /// </summary>
 /// <param name="exception">The exception to propagate.</param><param name="targetContext">The target context on which to propagate the exception.  Null to use the ThreadPool.</param>
 internal static void ThrowOnContext(Exception exception, SynchronizationContext targetContext)
 {
     if (targetContext != null)
     {
         try
         {
             targetContext.Post(state => throw TaskAwaiter.PrepareExceptionForRethrow((Exception)state), exception);
             return;
         }
         catch (Exception ex)
         {
             exception = new AggregateException(exception, ex);
         }
     }
     ThreadPool.QueueUserWorkItem(state => throw TaskAwaiter.PrepareExceptionForRethrow((Exception)state), exception);
 }