本文整理汇总了C#中Server.Exit方法的典型用法代码示例。如果您正苦于以下问题:C# Server.Exit方法的具体用法?C# Server.Exit怎么用?C# Server.Exit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Server
的用法示例。
在下文中一共展示了Server.Exit方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ServerThreadStart
public void ServerThreadStart()
{
try
{
Server server = new Server();
server.SaveFilenameOverride = savefilename;
server.exit = exit;
DummyNetServer netServer = new DummyNetServer();
netServer.SetPlatform(new GamePlatformNative());
netServer.SetNetwork(dummyNetwork);
server.mainSockets = new NetServer[3];
server.mainSockets[0] = netServer;
for (; ; )
{
server.Process();
Thread.Sleep(1);
platform.singlePlayerServerLoaded = true;
if (exit != null && exit.GetExit()) { server.Stop(); break; }
if (platform.singlepLayerServerExit)
{
// Exit thread and reset shutdown variable
server.Exit();
platform.singlepLayerServerExit = false;
}
}
exit.SetExit(false);
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
}
示例2: ChildServer
void ChildServer()
{
try
{
//Try to create the lockfile at startup
File.Create(lockFileName);
}
catch
{
Console.WriteLine("[SERVER] Lockfile could not be created! Shutdown will not work!");
}
server = new Server();
server.exit = new GameExit();
server.Public = true;
for (; ; )
{
server.Process();
Thread.Sleep(1);
//Check if server wants to exit
if (server.exit != null && server.exit.GetExit())
{
//If so, save data
server.Stop();
//Check if server wants to be restarted
if (!server.exit.GetRestart())
{
//Delete the lockfile if server wants to be shutdown
try
{
File.Delete(lockFileName);
}
catch
{
Console.WriteLine("[SERVER] Lockfile could not be deleted! Server will be restarted!");
}
}
//Finally kill the server process
return;
}
//Check if parent process is still running
if (!ENABLE_AUTORESTARTER)
{
//Only do so when automatic restarts are enabled
continue;
}
if (parentCheckStopwatch == null)
{
parentCheckStopwatch = new Stopwatch();
parentCheckStopwatch.Start();
}
if (parentCheckStopwatch.Elapsed.Milliseconds > 100)
{
try
{
Process.GetProcessById(parentid);
}
catch
{
//Shutdown the server if parent process could not be found
server.Exit();
return;
}
parentCheckStopwatch.Reset();
parentCheckStopwatch.Start();
}
}
}