Posted By

Verician on 09/26/12


Tagged

process kill


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

Priestd09
danfinrud55


Kill Named Process C#


 / Published in: C#
 

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.

  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
Posted By: Verician on September 26, 2012

Make sure you include the using statement (and reference if required):

using System.Diagnostics;

You need to login to post a comment.