// 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; namespace E { public class T { private object lck; public T(object lck) { this.lck = lck; } public void Run() { Console.WriteLine("Start"); Monitor.Enter(lck); Console.WriteLine("Done"); } } public class MainClass { public static void Main(string[] args) { object lck = new object(); T t = new T(lck); Monitor.Enter(lck); (new Thread(new ThreadStart(t.Run))).Start(); Thread.Sleep(100); Console.Write("Press enter to continue ..."); Console.ReadLine(); Monitor.Exit(lck); Thread.Sleep(100); } } }