user6667032 user6667032 - 4 months ago 20
C# Question

C#: Working with seperate .exe

I have a complex console program for data manipulation that's a pain to use.

I'm trying to create a wrapper type GUI program to facilitate ease of use.

Right now I'm opening a new thread and using Process.Start() and capturing the output.

This works great except for one issue, how do I cancel the process on demand from the user?

Given the fact the process is CPU intensive and can have long run times this is very important.

Answer

Use the Process.Kill() method:

foreach (var process in Process.GetProcessesByName("whatever"))
{
    process.Kill();
}

If you don't want to kill all the instances of whatever then start your process using:

process = Process.Start("whatever");

Then call the Kill method when you want to:

process.Kill();
Comments