I'm reading lock Statement (C# Reference) where I saw this code:
class Account
{
private Object thisLock = new Object();
//...
int Withdraw(int amount)
{
lock (thisLock)
{
//....
}
}
//...
}
I'm wondering if it would make any difference if we write lock(this) instead of lock(thisLock) in the above example. Please see the complete example if your answer depends on it.
If you think there is indeed some difference between lock(this) and lock(thisLock) , then please help me understanding the difference with all important points. In particular, what does each exactly mean?