// 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 X { private Thread worker; public X() { worker = new Thread(new ThreadStart(Run)); worker.Start(); } ~X() { Console.WriteLine("Bye bye"); } public void Run() { for(int i = 0; i < 10; i++) { Thread.Sleep(200); } } public void WaitToDone() { worker.Join(); } } public class TestClass { public static void Main(string[] args) { X o = new X(); Console.WriteLine("Started"); o.WaitToDone(); o = null; GC.Collect(); Thread.Sleep(100); Console.WriteLine("Ready to end"); } } }