0

I'm trying to start a process upon a button press and then stop it when another button is pressed in WPF. When I click the "Start" button, the process starts normally, but when I click the "Stop" button, the process keeps running (I don't get any errors). My code is below:

private Process _process;

private void StartProcess(object sender, RoutedEventArgs e) {
    string command = "/C .\\Miners\CryptoMiner1\Miner.exe";
    _process = Process.Start("cmd.exe", command);
}

private void StopProcess(object sender, RoutedEventArgs e) {
    _process.Kill();
}
Clemens
  • 123,504
  • 12
  • 155
  • 268
Chris Liu
  • 27
  • 5

1 Answers1

1

I found the solution. Instead of creating a cmd.exe process and then running the .exe from there, I directly ran the exe like so:

Before

string process = "/C Process.exe -args"
Process.Start("cmd.exe", process);

After

Process.Start("Process.exe", "-args");
Chris Liu
  • 27
  • 5