开发者

C# Pause/Stop System.Diagnostics.Process

开发者 https://www.devze.com 2023-01-21 12:58 出处:网络
I have a Process that runs an exe: Process pr = new Process(); pr.StartInfo.FileName = @\"wput.exe\"; etc

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 开发者_StackOverflowand 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
0

精彩评论

暂无评论...
验证码 换一张
取 消