Kill Named Process C#


/ Published in: C#
Save to your folder(s)

I built a middleware app to fire from an ERP addon, as part of the trigger process my app needed to close the ERP addon to reduce errors during a re-run of the event. I used this to kill the process.


Copy this code and paste it in your HTML
  1. public static void stopNamedProcess(string name)
  2. {
  3. foreach (Process p in System.Diagnostics.Process.GetProcessesByName(name))
  4. {
  5. try
  6. {
  7. p.Kill();
  8. p.WaitForExit();
  9. }
  10. catch (Exception exp)
  11. {
  12. Console.WriteLine(exp.Message);
  13. System.Diagnostics.EventLog.WriteEntry("AlchemySearch:KillProcess", exp.Message, System.Diagnostics.EventLogEntryType.Error);
  14. }
  15.  
  16. }
  17.  
  18. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.