From bb36d0f7bae94e360d31cc8d164544c44cf3cd4e Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Thu, 11 Jan 2018 05:46:37 +0000 Subject: [PATCH] Don't catch throw --- .../System/Threading/ThreadPoolScheduler.cs | 34 ++----------------- 1 file changed, 3 insertions(+), 31 deletions(-) diff --git a/src/System.IO.Pipelines/System/Threading/ThreadPoolScheduler.cs b/src/System.IO.Pipelines/System/Threading/ThreadPoolScheduler.cs index 7a82dd43025..617e9ad33cb 100644 --- a/src/System.IO.Pipelines/System/Threading/ThreadPoolScheduler.cs +++ b/src/System.IO.Pipelines/System/Threading/ThreadPoolScheduler.cs @@ -26,28 +26,14 @@ public override void Schedule(Action action, object state) // Queue to low contention local ThreadPool queue; rather than global queue as per Task Threading.ThreadPool.QueueUserWorkItem(_actionObjectAsTask, new ActionObjectAsTask(action, state), preferLocal: true); #elif NETSTANDARD2_0 - Threading.ThreadPool.QueueUserWorkItem(_actionObjectAsTask, new ActionObjectAsTask(action, state)); + Threading.ThreadPool.QueueUserWorkItem(_actionObjectAsTask, state); #else Task.Factory.StartNew(action, state); #endif } #if NETCOREAPP2_1 || NETSTANDARD2_0 - // Catches only the exception into a failed Task, so the fire-and-forget action - // can be queued directly to the ThreadPool without the extra overhead of as Task - private readonly static WaitCallback _actionAsTask = state => - { - try - { - ((Action)state)(); - } - catch (Exception ex) - { - // Create faulted Task for the TaskScheulder to handle exception - // rather than letting it escape onto the ThreadPool and crashing the process - Task.FromException(ex); - } - }; + private readonly static WaitCallback _actionAsTask = state => ((Action)state)(); private readonly static WaitCallback _actionObjectAsTask = state => ((ActionObjectAsTask)state).Run(); @@ -62,21 +48,7 @@ public ActionObjectAsTask(Action action, object state) _state = state; } - // Catches only the exception into a failed Task, so the fire-and-forget action - // can be queued directly to the ThreadPool without the extra overhead of as Task - public void Run() - { - try - { - _action(_state); - } - catch (Exception ex) - { - // Create faulted Task for the TaskScheulder to handle exception - // rather than letting it escape onto the ThreadPool and crashing the process - Task.FromException(ex); - } - } + public void Run() => _action(_state); } #endif }