C# Pause/Stop System.Diagnostics.Process – Education Career Blog

I have a Process that runs an 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 I can raise to achieve this. I have multiple Processes working in my app, each with it’s own Thread. I looked at pausing Threads but that would not give me the result I want.

,

You could read the list of processes in the system, as task manager does and try to kill the process with the name “wput.exe”.

Try this

using System.Diagnostics;


private void KillAllProcesses( string name )
{
    Process processes = Process.GetProcessesByName( name );
    foreach( Process p in processes )
        p.Kill();
}

,

To kill just started process use:

pr.Kill();

pr.WaitForExit();
// now you sure that it has been terminated

Leave a Comment