EventWaitHandle waitHandle = new EventWaitHandle(false, EventResetMode.AutoReset, "MyEvent"); waitHandle.Close();
using System.Threading; class Example { static EventWaitHandle waitHandle = new EventWaitHandle(false, EventResetMode.AutoReset); static void Main() { Thread workerThread = new Thread(Worker); workerThread.Start(); waitHandle.WaitOne(); Console.WriteLine("Worker thread completed."); } static void Worker() { // perform work here waitHandle.Set(); } }In this example, an EventWaitHandle is created and initialized as an auto-reset event. A worker thread is started and performs some work. Once the work is complete, the wait handle is signaled using the Set() method. The main thread waits for the wait handle to be signaled using WaitOne() method. Once the wait handle is signaled, the program continues running and prints "Worker thread completed." to the console. The System.Threading namespace is part of the .NET Framework class library.