Seems that MS have been promoting bad practice in some of their documentation...
http://msdn.microsoft.com/library/default.asp?url=/archive/en-us/dnaraskdr/html/askgui06032003.asp
Long and the short is don't lock on a type, so:
public class MyLockedType
{
public static void DoWork()
{
lock(typeof(MyLockedType))
{
...do something here
}
}
}
is bad and should be rewritten as:
public class MyLockedType
{
private static object mLockObj = new object();
public static void DoWork()
{
lock(mLockObj)
{
...do something here
}
}
}
There's more details in the article, but the main problem boils down to not having control over the MyLockedType to the extent that code outside of the class can lock on the type. Not only does this break the encapsulation but could lead to some very fun debugging.