I made a launcher for my ARK Server where I can easily change my settings and start.
I start the server with this:
Process serverprocess = new Process();
serverprocess.StartInfo.FileName = Path.GetFileName(serverpath);
serverprocess.StartInfo.Arguments = launch;
serverprocess.StartInfo.UseShellExecute = false;
serverprocess.Start();
serverprocess.WaitForExit();
But when I press CTRL+C it doesn’t wait until the ARK Server stops, it still runs in background while my app is killed.
I did some testing, the server recieves the shutdown signal and stops (which takes some time, espeically when the server isn’t fully started). But when it takes time to stop the server is still running while my app already closed.
Doublepressing CTRL+C will kill the server but since the first press already brings me out of the console I’m unable to doublepress.
Any idea how I can prevent my app from beeing closed while still stopping the ARK server?
Adding Console.TreatControlCAsInput = true;
will stop the server from even recieving the signal.
Thank you!
2
Answers
My test is ok
Process proc = new Process();
proc.StartInfo.FileName = “/bin/bash”;//sh
proc.StartInfo.Arguments = “-c ” ” + command + ” && echo ‘OK'””;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardOutput = true;
proc.Start();
You should properly close your program for it to close properly your server. Here you go: