nf313743
nf313743

Reputation: 4237

C# Pause/Stop System.Diagnostics.Process

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.

Upvotes: 2

Views: 4315

Answers (2)

abatishchev
abatishchev

Reputation: 100358

To kill just started process use:

pr.Kill();

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

Upvotes: 2

netadictos
netadictos

Reputation: 7720

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();
}

Upvotes: 3

Related Questions