using System.Threading.Tasks;
public static async Task Main()
var asyncLock = new ReentrantAsyncLock.ReentrantAsyncLock();
await using (await asyncLock.LockAsync(CancellationToken.None))
var contextBefore = SynchronizationContext.Current;
var contextAfter = SynchronizationContext.Current;
Console.WriteLine("AsyncTaskMethod is " + (contextBefore == contextAfter ? "okay" : "not okay"));
await using (await asyncLock.LockAsync(CancellationToken.None))
var contextBefore = SynchronizationContext.Current;
var contextAfter = SynchronizationContext.Current;
Console.WriteLine("TaskMethod is " + (contextBefore == contextAfter ? "okay" : "not okay"));
static Task TaskMethod(){
SynchronizationContext.SetSynchronizationContext(null);
static async Task AsyncTaskMethod(){
SynchronizationContext.SetSynchronizationContext(null);
await Task.Delay(1).ConfigureAwait(false);