当前位置: 首页>>代码示例>>C#>>正文


C# IServer.Stop方法代码示例

本文整理汇总了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);
            }
        }
开发者ID:vlsuKovalewVladimir,项目名称:modern-computer-technology,代码行数:42,代码来源:RunLabs.cs

示例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 ();
            }
        }
开发者ID:Evolutionary-Networking-Designs,项目名称:xsp,代码行数:43,代码来源:main.cs

示例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();
 }
开发者ID:SinaC,项目名称:TetriNET2,代码行数:8,代码来源:Program.cs


注:本文中的IServer.Stop方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。