Ejemplo n.º 1
0
 public void TestAbortThread()
 {
     Lock sync = new Lock();
     Condition aborted = new Condition(sync);
     Thread testThread = new Thread(delegate()
     {
         try
         {
             Log("Test thread sleeping for 8 seconds..");
             Thread.Sleep(8000);
             Fail("This line should never be executed");
         }
         catch (ThreadAbortException)
         {
             Log("Test thread aborted..");
             aborted.Signal();
         }
     });
     testThread.Start();
     sync.Acquire();
     Log("Aborting test thread in 2 seconds.  Sleeping...");
     Thread.Sleep(2000);
     Log("...awake!  Going to abort the test thread.");
     testThread.Abort();
     Log("Called testThread.Abort()");
     Assert("Thread was not aborted as expected!", aborted.Await(12000));
 }
Ejemplo n.º 2
0
 public void TestAbortThreadWithState()
 {
     Lock sync = new Lock();
     Condition aborted = new Condition(sync);
     Thread testThread = new Thread(delegate()
     {
         try
         {
             Log("Test thread sleeping for 8 seconds..");
             Thread.Sleep(8000);
             Fail("This line should never be executed");
         }
         catch (ThreadAbortException e)
         {
             if (e.ExceptionState != null && e.ExceptionState.ToString() == "Exception state")
             {
                 Log("Test thread aborted with state: " + e.ExceptionState);
                 aborted.Signal();
             }
             else
             {
                 Log("Test thread aborted with unknown state: " + e.ExceptionState);
             }
         }
     });
     testThread.Start();
     sync.Acquire();
     Log("Aborting test thread in 2 seconds");
     Thread.Sleep(2000);
     testThread.Abort("Exception state");
     Assert("Thread was not aborted as expected!", aborted.Await(12000));
 }