开发者

Run more than 1 process in Process Class

开发者 https://www.devze.com 2023-03-27 21:38 出处:网络
Well, it will be a bit hard to explain what i need to do here, but it goes like this: I am building a program that will need to run .exe (From different folders).

Well, it will be a bit hard to explain what i need to do here, but it goes like this:

I am building a program that will need to run .exe (From different folders).

How can i do this, that i will be able to do Process.start(), but i will be able to kill it as well?

I mean, if I do:

System.Diagnostics.Process process;
process = process.start();

Then I can do Process.Kill(); but what if I dont know how many processes I have? How can I do more and more processes with the ability to kill them?

Is this even possible?

I am h开发者_Python百科oping i explained it correctly. I am not sure how I can explain it better :O


You can store the created processes in a list to track them. Remove them from the list when you kill them:

var list = new List<Process>();

var p1 = Process.Start(...);
list.Add(p1);
// similarly for other processes, or run this in a loop

// later...
var p = list[0];
p.Kill();
list.Remove(p);
// ...

You can also use other specialized collections (like a queue) if that makes more sense.

0

精彩评论

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