C # Pause / Stop System.Diagnostics.Process

I have a process that starts exe:

Process pr = new Process(); pr.StartInfo.FileName = @"wput.exe"; 

etc.

I want to be able to pause and stop this process. Are there any events that I can do to achieve this. I have several processes running in my application, each of which has its own thread. I was looking at pausing threads, but that would not give me the result I want.

+2
source share
2 answers

You can read the list of processes in the system, as the task manager does, and try to kill the process named "wput.exe".

try it

 using System.Diagnostics; private void KillAllProcesses( string name ) { Process[] processes = Process.GetProcessesByName( name ); foreach( Process p in processes ) p.Kill(); } 
+2
source

To kill just started using a process:

 pr.Kill(); pr.WaitForExit(); // now you sure that it has been terminated 
+2
source

Source: https://habr.com/ru/post/1401133/


All Articles