internal static Exception HandleUnexpectedTaskResult (Task task)
{
+ var slot = task.ExceptionSlot;
switch (task.Status) {
case TaskStatus.Canceled:
// Use original exception when we have one
- if (task.ExceptionSlot.Exception != null)
+ if (slot.Exception != null)
goto case TaskStatus.Faulted;
return new TaskCanceledException (task);
case TaskStatus.Faulted:
- return task.ExceptionSlot.Exception.InnerException;
+ // Mark the exception as observed when GetResult throws
+ slot.Observed = true;
+ return slot.Exception.InnerException;
default:
throw new ArgumentException (string.Format ("Unexpected task `{0}' status `{1}'", task.Id, task.Status));
}
internal static void HandleOnCompleted (Task task, Action continuation, bool continueOnSourceContext, bool manageContext)
{
- if (continueOnSourceContext && SynchronizationContext.Current != null) {
+ if (continueOnSourceContext && SynchronizationContext.Current != null && SynchronizationContext.Current.GetType () != typeof (SynchronizationContext)) {
task.ContinueWith (new SynchronizationContextContinuation (continuation, SynchronizationContext.Current));
} else {
IContinuation cont;
Task cont_task;
- if (TaskScheduler.Current != TaskScheduler.Default) {
+ if (continueOnSourceContext && !TaskScheduler.IsDefault) {
cont_task = new Task (TaskActionInvoker.Create (continuation), null, CancellationToken.None, TaskCreationOptions.None, null);
cont_task.SetupScheduler (TaskScheduler.Current);
cont = new SchedulerAwaitContinuation (cont_task);
} else {
cont_task = null;
- cont = new ActionContinuation (continuation);
+ cont = new AwaiterActionContinuation (continuation);
}
//
cont_task.SetupScheduler (TaskScheduler.Current);
}
- cont_task.Schedule ();
+ cont_task.Schedule (true);
}
}