// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Threading; class MainClass { public static object lockobject = "*"; public static void Main(string[] args) { (new Thread(new ThreadStart(Locker))).Start(); for(int i = 0; i < 6; i++) { Thread.Sleep(1000); Console.WriteLine(Monitor.TryEnter(lockobject)); } } public static void Locker() { lock(lockobject) { Thread.Sleep(5000); } } }