Skip to content

Instantly share code, notes, and snippets.

@kevingosse
Created February 1, 2019 13:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevingosse/2592ee3da25ac1d44ed7d3c64b34f2a2 to your computer and use it in GitHub Desktop.
Save kevingosse/2592ee3da25ac1d44ed7d3c64b34f2a2 to your computer and use it in GitHub Desktop.
protected override void QueueTask(Task task)
{
MutateState(task);
var newScheduler = new ThreadPoolTaskScheduler();
typeof(Task).GetField("m_taskScheduler", BindingFlags.Instance | BindingFlags.NonPublic)
.SetValue(task, newScheduler);
ThreadPool.UnsafeQueueUserWorkItem(t => newScheduler.ExecuteTask((Task)t), task);
}
private void ExecuteTask(Task t)
{
TryExecuteTask(t);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment