public override void Run() { while (!finish) { try { TransactionalMethod(); TransactionalMethod(); InterruptableMethod(); TransactionalMethod(); InterruptableMethod(); // Make sure these don't throw System.Threading.ThreadInterruptedException Assert.IsFalse(UninterruptableMonitor.IsEntered(lock1)); Assert.IsFalse(UninterruptableMonitor.IsEntered(lock2)); Assert.IsFalse(UninterruptableMonitor.IsEntered(lock3)); if (UninterruptableMonitor.TryEnter(lock1)) { try { Assert.IsTrue(UninterruptableMonitor.IsEntered(lock1)); } finally { UninterruptableMonitor.Exit(lock1); } } allowInterrupt = true; } catch (Util.ThreadInterruptedException re) { // Success - we received the correct exception type Console.WriteLine("TEST: got interrupt"); Console.WriteLine(GetToStringFrom(re)); Exception e = re.InnerException; Assert.IsTrue(e is System.Threading.ThreadInterruptedException); // Make sure we didn't interrupt in the middle of a transaction Assert.IsFalse(transactionInProgress); if (finish) { break; } } catch (Exception t) when(t.IsThrowable()) { Console.WriteLine("FAILED; unexpected exception"); Console.WriteLine(GetToStringFrom(t)); // Make sure we didn't error in the middle of a transaction Assert.IsFalse(transactionInProgress); failed = true; break; } } }