Created
February 1, 2019 12:55
-
-
Save kevingosse/a26e0756d0947f954d65f88129eeeafb to your computer and use it in GitHub Desktop.
This file contains 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
internal class StartupHook | |
{ | |
public static void Initialize() | |
{ | |
typeof(Task).GetField("s_asyncDebuggingEnabled", BindingFlags.Static | BindingFlags.NonPublic) | |
.SetValue(null, true); | |
typeof(TaskScheduler).GetField("s_defaultTaskScheduler", BindingFlags.Static | BindingFlags.NonPublic) | |
.SetValue(null, new ThreadPoolTaskScheduler()); | |
} | |
[DebuggerDisplay("ThreadPoolTaskScheduler")] | |
class ThreadPoolTaskScheduler : TaskScheduler | |
{ | |
protected override IEnumerable<Task> GetScheduledTasks() | |
{ | |
throw new NotImplementedException(); | |
} | |
protected override void QueueTask(Task task) | |
{ | |
MutateState(task); | |
ThreadPool.UnsafeQueueUserWorkItem(t => TryExecuteTask((Task)t), task); | |
} | |
private void MutateState(Task task) | |
{ | |
// TODO | |
} | |
protected override bool TryExecuteTaskInline(Task task, bool taskWasPreviouslyQueued) | |
{ | |
MutateState(task); | |
return TryExecuteTask(task); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment