本文整理汇总了C#中IServer.Stop方法的典型用法代码示例。如果您正苦于以下问题:C# IServer.Stop方法的具体用法?C# IServer.Stop怎么用?C# IServer.Stop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IServer
的用法示例。
在下文中一共展示了IServer.Stop方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Run
public void Run(string[] args, IServer server, IClient client)
{
try
{
TypeApp typeApp = (args[0] == "-s") ? TypeApp.Server : (args[0] == "-c") ? TypeApp.Client : TypeApp.None;
IPAddress ipAdress;
IPEndPoint ipEndPoint;
switch (typeApp)
{
case TypeApp.Client:
ipAdress = IPAddress.Parse(args[1]);
ipEndPoint = new IPEndPoint(ipAdress, int.Parse(args[2]));
client.ipEndPoint = ipEndPoint;
client.Start();
break;
case TypeApp.Server:
ipAdress = IPAddress.Any;
ipEndPoint = new IPEndPoint(ipAdress, int.Parse(args[1]));
server.ipEndPoint = ipEndPoint;
server.Start();
Console.ReadKey(true);
server.Stop();
break;
case TypeApp.None:
throw new Exception("Не указан тип приложения (-c или -s)");
}
}
catch (IndexOutOfRangeException)
{
Console.WriteLine("Неверные параметры");
}
catch (Exception e)
{
Console.WriteLine("Ошибка: {0}", e.Message);
System.Diagnostics.Debug.WriteLine(e.StackTrace);
}
}
示例2: CreateWatchdog
static void CreateWatchdog(ConfigurationManager configurationManager, IServer server)
{
using (var aliveLock = new System.Threading.ReaderWriterLockSlim ()) {
bool alive = false;
// On a new connection try to set alive to true
// If we can't then don't bother, it's not needed
server.RequestReceived += (sender, e) =>
TryRunLocked (
() => aliveLock.TryEnterWriteLock (0),
() => alive = true,
aliveLock.ExitWriteLock
);
var pluto = new Watchdog (configurationManager.IdleTime * 1000);
pluto.End += (sender, e) => {
Logger.Write (LogLevel.Debug, "The dog bit!");
server.Stop ();
Logger.Write (LogLevel.Debug, "Server stopped.");
Logger.Write (LogLevel.Debug, "Goodbye!");
Environment.Exit (0);
};
// Check every second for hearthbeats
var t = new Timer (1000);
t.Elapsed += (sender, e) =>
RunLocked (
aliveLock.EnterUpgradeableReadLock,
() => {
if (!alive)
return;
RunLocked (
aliveLock.EnterWriteLock,
() => alive = false,
aliveLock.ExitWriteLock
);
pluto.Kick ();
},
aliveLock.ExitUpgradeableReadLock
);
t.Start ();
}
}
示例3: ServerOnPerformRestartServer
private static void ServerOnPerformRestartServer(IServer server)
{
// TODO
server.Stop();
Console.WriteLine("Waiting 5 seconds before restarting");
System.Threading.Thread.Sleep(5000);
server.Start();
}