I am talking about how considerate C # programmer, rather than .NET Framework.
This is the use of the C # minor effort Monitor:
MyClass obj;
// s Some code to the initialize obj;
Lock (obj)
{
obj.DoSomething ();
}
The above code is equivalent to the following, how, C # considerate not?
Obj MyClass;
// s Some code to the initialize obj;
the Monitor.Enter (obj);
the try
{
obj.DoSomething ();
}
the finally
{
. Monitor the Exit (obj);
}
(按:code source from <<Programming .NET Components>> 2nd.Edition Juval Lowy)
Reproduced in: https: //www.cnblogs.com/jamesleng/archive/2011/10/20/2217607.html