Skip to content

Instantly share code, notes, and snippets.

@i3arnon
Created October 6, 2015 21:14
Show Gist options
  • Save i3arnon/c311c186b60825f26af2 to your computer and use it in GitHub Desktop.
Save i3arnon/c311c186b60825f26af2 to your computer and use it in GitHub Desktop.
ThreadPoolTaskScheduler.QueueTask creates a new thread for TaskCreationOptions.LongRunning
protected internal override void QueueTask(Task task)
{
if ((task.Options & TaskCreationOptions.LongRunning) != 0)
{
// Run LongRunning tasks on their own dedicated thread.
Thread thread = new Thread(s_longRunningThreadWork);
thread.IsBackground = true; // Keep this thread from blocking process shutdown
thread.Start(task);
}
else
{
// Normal handling for non-LongRunning tasks.
bool forceToGlobalQueue = ((task.Options & TaskCreationOptions.PreferFairness) != 0);
ThreadPool.UnsafeQueueCustomWorkItem(task, forceToGlobalQueue);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment