Created
October 6, 2015 21:14
-
-
Save i3arnon/c311c186b60825f26af2 to your computer and use it in GitHub Desktop.
ThreadPoolTaskScheduler.QueueTask creates a new thread for TaskCreationOptions.LongRunning
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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