What is the difference between locking on a type of a class vs locking on the class itself?
For example:
private readonly object xmpp = new object();
lock (xmpp)
{
...
}
vs
lock (typeof(Xmpp))
{
...
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
lock(x)synchronizes on a different lock for each instance of the typelock(typeof(X))synchronizes on the same lock for all instances of the typeAlways lock on a private lock object:
If you must synchronize access to class static members, use the same pattern: