public async Task StopRunLoopAsync() { if (!LoopRunning) { return; } Console.WriteLine("Stopping Minecraft Server Run Loop"); Stop(true); ServerRunLoop.Stop(); Console.WriteLine("Minecraft Server Run Loop Stopped"); }
private void ServerRunLoop_LoopIterationEvent(CancellationToken token) { try { StartServer().Wait(); } catch (Exception e) { Console.WriteLine(string.Format("Encountered exception while Starting Server as part of Run Loop = {0}", e)); } if (ServerProcess != null) { ServerProcess.WaitForExit(); HandleServerExit(ServerProcess.ExitCode); } else { ++ConsecutiveErrors; } if (ConsecutiveErrors > 0 && !IsErrored) { Console.WriteLine(string.Format("Minecraft Server has hit an error - Consecutive Errors = {0}, ErrorMax = {1}", ConsecutiveErrors, ConsecutiveErrorMax)); } if (IsErrored) { Console.WriteLine(string.Format("Minecraft Server is now in Errored State - Consecutive Errors = {0}, ErrorMax = {1}", ConsecutiveErrors, ConsecutiveErrorMax)); SetStatus(ServerStatus.Error); ServerRunLoop.Stop(); } Console.WriteLine("Sleeping for 10s"); TimeSpan sleep = TimeSpan.FromSeconds(10); const int iterations = 100; for (int i = 0; i < iterations && !token.IsCancellationRequested; ++i) { Thread.Sleep(sleep.Divide(iterations)); token.ThrowIfCancellationRequested(); } }