The corresponding code snippet you are looking for is inside the internal Task.SetContinuationForAwait method:
In fact, he performs two checks, first sees that it is not null , but the second, to make sure that this is not the default SynchronizationContext , which, in my opinion, is the key point here.
If you open a console application and try to extract SynchronizationContext.Current , you will definitely see that it can be null .
class Program { public static void Main(string[] args) { Console.WriteLine(SynchronizationContext.Current == null ? "NoContext" : "Context!"); } }
source share