Пример #1
0
 private void Run(Action action, ScriptEngine engine)
 {
     Exception e = null;
     var t = new Thread((ThreadStart)delegate
     {
         try
         {
             action();
         }
         catch (Exception ex)
         {
             if (ex is ThreadAbortException)
                 e = new TimeoutException("The method was aborted.");
             else
                 e = ex;
         }
     });
     t.Start();
     if (!t.Join(TimeSpan.FromSeconds(10)))
     {
         Console.WriteLine("This is abort!");
         engine.ShutDown();
         t.Abort();
         Console.WriteLine("Aborted!");
         throw new TimeoutException("Operation timed out.");
     }
     if (e != null)
     {
         throw e;
     }
 }