kill a process on hitting stop button

I have this code:
Process p = Process.GetProcessByName("notepad").FirstofDefault();
if( p == null ) p = Process.Start("notepad.exe");
I wish to kill this p on hitting the stop button, how do I do that? thanks!

Comments

  • JoeAlbahari
    edited September 2015
    Instead of calling Process.Start, call Util.Cmd ("notepad.exe");

    If the process already exists, you could subscribe to the Util.Cleanup event to terminate it.