X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fclass%2Fcorlib%2FSystem.Threading.Tasks%2FTask.cs;h=bb023257b4769978f0db08de9d5a5a4a03119811;hb=a0173a7e76ad48889ade46116e516731b170e7c5;hp=8d75e83951681a17270a77139a161ed1f349233a;hpb=eee540621a25b57dbad6a41dd62a559e43a766c1;p=mono.git diff --git a/mcs/class/corlib/System.Threading.Tasks/Task.cs b/mcs/class/corlib/System.Threading.Tasks/Task.cs index 8d75e839516..bb023257b47 100644 --- a/mcs/class/corlib/System.Threading.Tasks/Task.cs +++ b/mcs/class/corlib/System.Threading.Tasks/Task.cs @@ -186,7 +186,7 @@ namespace System.Threading.Tasks throw new InvalidOperationException ("Start may not be called on a promise-style task"); SetupScheduler (scheduler); - Schedule (); + Schedule (true); } internal void SetupScheduler (TaskScheduler scheduler) @@ -214,10 +214,10 @@ namespace System.Threading.Tasks if (IsPromise) throw new InvalidOperationException ("RunSynchronously may not be called on a promise-style task"); - RunSynchronouslyCore (scheduler); + RunSynchronouslyCore (scheduler, true); } - internal void RunSynchronouslyCore (TaskScheduler scheduler) + internal void RunSynchronouslyCore (TaskScheduler scheduler, bool throwException) { SetupScheduler (scheduler); Status = TaskStatus.WaitingToRun; @@ -228,10 +228,13 @@ namespace System.Threading.Tasks } catch (Exception inner) { var ex = new TaskSchedulerException (inner); TrySetException (new AggregateException (ex), false, true); - throw ex; + if (throwException) + throw ex; + + return; } - Schedule (); + Schedule (throwException); WaitCore (Timeout.Infinite, CancellationToken.None, false); } #endregion @@ -381,10 +384,17 @@ namespace System.Threading.Tasks #endregion #region Internal and protected thingies - internal void Schedule () + internal void Schedule (bool throwException) { Status = TaskStatus.WaitingToRun; - scheduler.QueueTask (this); + try { + scheduler.QueueTask (this); + } catch (Exception inner) { + var ex = new TaskSchedulerException (inner); + TrySetException (new AggregateException (ex), false, true); + if (throwException) + throw ex; + } } void ThreadStart () @@ -687,8 +697,13 @@ namespace System.Threading.Tasks return true; // If the task is ready to be run and we were supposed to wait on it indefinitely without cancellation, just run it - if (runInline && Status == TaskStatus.WaitingToRun && millisecondsTimeout == Timeout.Infinite && scheduler != null && !cancellationToken.CanBeCanceled) - scheduler.RunInline (this, true); + if (runInline && Status == TaskStatus.WaitingToRun && millisecondsTimeout == Timeout.Infinite && scheduler != null && !cancellationToken.CanBeCanceled) { + try { + scheduler.RunInline (this, true); + } catch (Exception e) { + throw new TaskSchedulerException (e); + } + } bool result = true;