// 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 Mutex mtx = new Mutex(); 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 mutex mtx.WaitOne(); Console.WriteLine("all done"); mtx.ReleaseMutex(); } public static void Run() { Console.WriteLine("start thread"); mtx.WaitOne(); Thread.Sleep(5000); mtx.ReleaseMutex(); Console.WriteLine("end thread"); } }