Can we have a method IsInAsyncContext
that identifies if the control is inside an async execution flow or not? Check the following usage.
public static void Main(){ IsInAsyncContext(); // Should return false. AsyncMethod().GetAwaiter().GetResult(); SyncMethod();}private static async Task AsyncMethod(){ IsInAsyncContext(); // Should return true. SyncMethod();}private static void SyncMethod(){ // Should return false if called from Main, true if called from AsyncMethod. IsInAsyncContext();}