ManualResetEvent mre = new ManualResetEvent(false); mre.WaitOne(); // waits indefinitely until signal is set
ManualResetEvent mre = new ManualResetEvent(false); bool result = mre.WaitOne(5000); // waits for 5 seconds until signal is set if (result) { Console.WriteLine("Signal set"); } else { Console.WriteLine("Timed out waiting for signal"); }In this example, the WaitOne method is called with a timeout of 5000 milliseconds. If the signal is not set within the specified time, the method returns false and the console writes "Timed out waiting for signal". The System.Threading.ManualResetEvent class is part of the System.Threading namespace in the .NET Framework.