X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fclass%2Fcorlib%2FSystem.Runtime.CompilerServices%2FTaskAwaiter.cs;h=80b64cb56e841ac167288eb742725eca27a91d6b;hb=3fb128ac0de7cca459098c2dc3359d81f5e48353;hp=de54a75025769ed625a180f0e0b7d9c6dd3fd2f0;hpb=6cce4a3937d2b007d2d2edfb245cc1f5c66a3d95;p=mono.git diff --git a/mcs/class/corlib/System.Runtime.CompilerServices/TaskAwaiter.cs b/mcs/class/corlib/System.Runtime.CompilerServices/TaskAwaiter.cs index de54a750257..80b64cb56e8 100644 --- a/mcs/class/corlib/System.Runtime.CompilerServices/TaskAwaiter.cs +++ b/mcs/class/corlib/System.Runtime.CompilerServices/TaskAwaiter.cs @@ -64,9 +64,13 @@ namespace System.Runtime.CompilerServices { switch (task.Status) { case TaskStatus.Canceled: + // Use original exception when we have one + if (task.ExceptionSlot.Exception != null) + goto case TaskStatus.Faulted; + return new TaskCanceledException (task); case TaskStatus.Faulted: - return task.Exception.InnerException; + return task.ExceptionSlot.Exception.InnerException; default: throw new ArgumentException (string.Format ("Unexpected task `{0}' status `{1}'", task.Id, task.Status)); } @@ -74,18 +78,18 @@ namespace System.Runtime.CompilerServices 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); } // @@ -100,7 +104,7 @@ namespace System.Runtime.CompilerServices cont_task.SetupScheduler (TaskScheduler.Current); } - cont_task.Schedule (); + cont_task.Schedule (true); } }