The C# using
statement requires that the used expression implement IDisposable
.
Because Task<T>
implements IDisposable
, one may accidentally omit an await
operator
and Dispose
of the Task<T>
instead of the T
result itself when T
derives from IDisposable
.
AsyncSemaphore lck;
using (lck.EnterAsync())
{
// ...
}
Add the await
operator within the using
expression.
AsyncSemaphore lck;
using (await lck.EnterAsync())
{
// ...
}