I am not clear (and can't find documentation clear enough): when using the lock
keyword in an async
method: will the thread be blocked if the object is already blocked or will it return a task in suspended state (not blocking the thread, and returning when the lock is released)?
In the code below, will the line block the thread? If it blocks the thread (which is what I think), is there an standard not blocking solution? I am considering using AsyncLock, but first I wanted to try for something standard.
private object myLock = new object();
private async Task MyMethod1()
{
lock (myLock) // <---- will this line cause a return of the current method
// as an Await method call would do if myLock was already locked?
{
//....
}
}
// other methods that lock on myLock