Friday, June 22, 2012

Terminate Process that encounters an error

Simply set the error data received and terminate the process.
Code:
      private void button2_Click(object sender, EventArgs e)  
      {  
        foreach (Process p in Process.GetProcesses())  
        {  
          p.ErrorDataReceived += new DataReceivedEventHandler  
            (p_ErrorDataReceived);  
        }  
      }  

      void p_ErrorDataReceived(object sender, DataReceivedEventArgs e)  
      {  
        Process p = (Process)sender;  
        p.Kill();  
     } 

0 comments:

Post a Comment