How can I prevent synchronous continuations on a Task?
New in .NET 4.6: .NET 4.6 contains a new TaskCreationOptions: RunContinuationsAsynchronously. Since you’re willing to use Reflection to access private fields… You can mark the TCS’s Task with the TASK_STATE_THREAD_WAS_ABORTED flag, which would cause all continuations not to be inlined. const int TASK_STATE_THREAD_WAS_ABORTED = 134217728; var stateField = typeof(Task).GetField(“m_stateFlags”, BindingFlags.NonPublic | BindingFlags.Instance); stateField.SetValue(task, (int) stateField.GetValue(task) … Read more