public void ThreadInterruptTest() { var stayAwake = new StayAwake(); var newThread = new Thread(stayAwake.ThreadMethod); newThread.Start(); Thread.Sleep(1000); // The following line causes an exception to be thrown // in ThreadMethod if newThread is currently blocked // or becomes blocked in the future. newThread.Interrupt(); if (log.IsInfoEnabled) { log.Info("2. Main thread calls Interrupt on newThread."); } // Tell newThread to go to sleep. stayAwake.SleepSwitch = true; // Wait for newThread to end. newThread.Join(); Assert.IsFalse(newThread.IsAlive); }
public void ThreadInterruptTest() { var stayAwake = new StayAwake(); var newThread = new Thread(stayAwake.ThreadMethod); newThread.Start(); Thread.Sleep(1000); // The following line causes an exception to be thrown // in ThreadMethod if newThread is currently blocked // or becomes blocked in the future. newThread.Interrupt(); if(log.IsInfoEnabled) log.Info("2. Main thread calls Interrupt on newThread."); // Tell newThread to go to sleep. stayAwake.SleepSwitch = true; // Wait for newThread to end. newThread.Join(); Assert.IsFalse(newThread.IsAlive); }