Example
using System; using System.Threading; namespace Samples { public class WaitHandle { static AutoResetEvent threadDone = new AutoResetEvent(false); public static void StartHere() { Console.WriteLine("Starting thread"); Thread.Sleep(1000); threadDone.Set(); Console.WriteLine("Finishing thread"); } public static void Main() { Console.WriteLine("Starting Main"); Thread t = new Thread( new ThreadStart(StartHere)); t.Start(); threadDone.WaitOne(); threadDone.Close(); Console.WriteLine("Finishing Main"); } } }
Starting Main Starting thread Finishing Main Finishing thread
Get .NET Framework Standard Library Annotated Reference, Volume 1: Base Class Library and Extended Numerics Library now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.