lock (x) ...where x is an expression of a reference-type, is precisely equivalent to
System.Threading.Monitor.Enter(x); try { ... } finally { System.Threading.Monitor.Exit(x); }except that x is only evaluated once. [Example: The System.Type object of a class can conveniently be used as the mutual-exclusion lock for static methods of the class. For example:
class Cache { public static void Add(object x) { lock (typeof(Cache)) { ... } } public static void Remove(object x) { lock (typeof(Cache)) { ... } } }end example]
| |
Jagger Software Ltd | |
Company # 4070126 | |
VAT # 762 5213 42 |