Handling Events on System.Diagnostics.Process

If you want to handle events when working with System.Diagnostics.Process -- for example, the Exited event -- you have to first enable the raising of events using the EnableRaisingEvents property on Process.


   1:  using System.Diagnostics;
   2:   
   3:  class MyClass
   4:  {
   5:      void RunProcess()
   6:      {
   7:          Process p = new Process();
   8:          p.EnableRaisingEvents = true;
   9:          p.Exited += new EventHander(Process_Exited);
  10:      }
  11:   
  12:  }

Comments

Popular posts from this blog

Using NHibernate in Asp.Net Core

Adding New Microsoft Extensions to Legacy WCF and ASMX Web Services

Code Coverage for Multiple Projects in a Single Build using Dotnet Test and Coverlet