skip to Main Content

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


  1. 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();

    Login or Signup to reply.
  2. You should properly close your program for it to close properly your server. Here you go:

    var serverProcess = Process.Start(new ProcessStartInfo
    {
        FileName = Path.GetFileName(serverpath),
        Arguments = launch,
        UseShellExecute = false
    });
    
    while (Console.ReadLine() != "exit")
    {
        Thread.Sleep(500);
    }
    
    serverProcess.Close();
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search