Shaolinq icon indicating copy to clipboard operation
Shaolinq copied to clipboard

AsyncRewriter generates invalid code within a lock

Open samcook opened this issue 7 years ago • 0 comments

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();
}

samcook avatar May 08 '17 10:05 samcook