1

I am working on a simple UI for the ccminer. As part of my launch/shutdown I use something like this to launch the ccminer.exe:

ProcessStartInfo info = new ProcessStartInfo();
info.FileName = “ccminer.exe”
info.Arguments = "start";
info.UseShellExecute = false;
info.CreateNoWindow = true;
Process.Start(info);

When I need to stop it I just call kill(). Now, the problem is that this way, half of the time the console app crashes my video driver and does not gracefully shutdown.

If I were to run ccminer as a console app, I would hit CTRL+C and then it would ask something like: “Terminate, Y/N?” and upon receiving a confirmation - gracefully halt without crashing the video driver.

Is there a way I can programmatically mimic this graceful CTRL+C shutdown without simply killing my process?

Cœur
  • 37,241
  • 25
  • 195
  • 267
eYe
  • 1,695
  • 2
  • 29
  • 54
  • 1
    [This](https://stackoverflow.com/a/15281070/21567) might do want you want. – Christian.K Mar 26 '18 at 04:14
  • You should use Environment.Exit(0); https://stackoverflow.com/a/10286091/7810515 – Drew Sumido Mar 26 '18 at 05:28
  • @DrewSumido This terminates a console application from its own code, yes. But that is not what's being asked here. – Thorsten Dittmar Mar 26 '18 at 10:18
  • "Graceful" is not an option when a console mode app can crash a video driver. You need to get the computer fixed. – Hans Passant Mar 26 '18 at 11:14
  • @HansPassant ccminer works directly with the video driver, so halting it without a proper interrupt and resources release inevitably causes a video driver crash – eYe Mar 26 '18 at 11:28
  • Process.Kill() is not fundamentally different from pressing Ctrl+C or Ctrl+Break. If Ctrl+C does not cause a crash then consider to pinvoke GenerateConsoleCtrlEvent(). If it does then you'll have to make it graceful by allowing the user to easily stop the program with, say, the Escape key. – Hans Passant Mar 26 '18 at 11:37

0 Answers0