Shaolinq
Shaolinq copied to clipboard
AsyncRewriter generates invalid code within a lock
AsyncRewriter inserts async method calls inside code that is within a lock section, however this won't compile (Cannot await in the body of a lock statement
):
lock (lockObj)
{
// can't do this inside a lock
await this.MethodAsync(cancellationToken).ConfigureAwait(false);
}
Can be worked around by using something like SemaphoreSlim
instead:
await semaphoreSlim.WaitAsync();
try
{
// synchronised code here
}
finally
{
semaphoreSlim.Release();
}