Skip to content
This repository has been archived by the owner on Aug 2, 2023. It is now read-only.

Commit

Permalink
Don't catch throw
Browse files Browse the repository at this point in the history
  • Loading branch information
benaadams committed Jan 11, 2018
1 parent f3ffc2b commit bb36d0f
Showing 1 changed file with 3 additions and 31 deletions.
34 changes: 3 additions & 31 deletions src/System.IO.Pipelines/System/Threading/ThreadPoolScheduler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,14 @@ public override void Schedule(Action<object> 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();

Expand All @@ -62,21 +48,7 @@ public ActionObjectAsTask(Action<object> 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
}
Expand Down

0 comments on commit bb36d0f

Please sign in to comment.