// 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 o = new object(); public static void Main(string[] args) { Console.WriteLine("ready to start thread"); (new Thread(new ThreadStart(Run))).Start(); Thread.Sleep(1); // make sure thread gets monitor Monitor.Enter(o); Console.WriteLine("all done"); Monitor.Exit(o); } public static void Run() { Console.WriteLine("start thread"); Monitor.Enter(o); Thread.Sleep(5000); Monitor.Exit(o); Console.WriteLine("end thread"); } }