Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Untitled

a guest Jun 18th, 2018 51 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. while (true)
  2.         {
  3.             //keep checking if timer expired or app closed externally (ie. by user)
  4.             if (dtEndTime <= DateTime.Now || p.HasExited)
  5.             {
  6.                 if (!p.HasExited)
  7.                     p.Kill();
  8.                 break;
  9.             }
  10.             System.Threading.Thread.Sleep(500);
  11.         }
  12.    
  13. try
  14. {
  15.     if(!p.HasExited)
  16.     {
  17.         p.Kill();
  18.     }
  19.     break;
  20. }
  21. catch(Exception ex)
  22. {
  23.     System.Diagnostics.Trace.WriteLine(String.Format("Could not kill process {0}, exception {1}", p.ToString(), ex.ToString()));
  24. }
  25.    
  26. using System;
  27. public class MyClass
  28. {
  29.     public static void Main()
  30.     {
  31.         System.AppDomain.CurrentDomain.UnhandledException += MyExceptionHandler;
  32.         System.Threading.ThreadPool.QueueUserWorkItem(DoWork);
  33.         Console.ReadLine();
  34.     }
  35.  
  36.     private static void DoWork(object state)
  37.     {
  38.         throw new ApplicationException("Test");
  39.     }
  40.  
  41.     private static void MyExceptionHandler(object sender, System.UnhandledExceptionEventArgs e)
  42.     {
  43.         // get the message
  44.         System.Exception exception = e.ExceptionObject as System.Exception;
  45.         Console.WriteLine("Unhandled Exception Detected");
  46.         if(exception != null)
  47.             Console.WriteLine("Message: {0}", exception.Message);
  48.         // for this console app, hold the window open until I press enter
  49.         Console.ReadLine();
  50.     }
  51.  
  52. }
  53.    
  54. p.WaitForInputIdle(10000);
  55. am.hWnd = p.MainWindowHandle;
  56.    
  57. while (true)
  58. {
  59.    //keep checking if timer expired or app closed externally (ie. by user)
  60.    if (dtEndTime <= DateTime.Now || p.HasExited)  {
  61.       try {
  62.           if (!p.HasExited)  // if the app hasn't already exitted...
  63.           {
  64.              if (!p.CloseMainWindow())  // did message get sent?
  65.              {
  66.                 if (!p.HasExited)  //has app closed yet?
  67.                 {
  68.                    p.Kill();  // force app to exit
  69.                    p.WaitForExit(2000);  // a few moments for app to shut down
  70.                 }
  71.              }
  72.              p.Close();  // free resources
  73.           }                        
  74.        }
  75.       catch { // blah blah }
  76.       break;
  77.    }
  78.    System.Threading.Thread.Sleep(500);
  79. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top