Ejemplo n.º 1
0
 protected override void OnStop()
 {
     // TODO:  在此处添加代码以执行停止服务所需的关闭操作。
     if (mMonitorServer != null)
     {
         mMonitorServer.Stop();
     }
     WriteLog(LogMode.Info, string.Format("Service stopped"));
     if (mLogOperator != null)
     {
         mLogOperator.Stop();
         mLogOperator = null;
     }
 }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            if (args != null && args.Length > 0)
            {
                if (args[0].ToUpper() == "C")
                {
                    //以控制台运行
                    try
                    {
                        IsConsole = true;
                        MonitorServer MonitorServer = new MonitorServer();
                        MonitorServer.Debug += MonitorServer_Debug;
                        //调试模式
                        if (args.Length > 1 && args[1].ToUpper() == "D")
                        {
                            IsDebug = true;
                        }
                        MonitorServer.Start();
                        Console.ReadLine();
                        MonitorServer.Stop();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                    return;
                }
            }
            //以Windows服务器运行
            MonitorService MonitorService = new MonitorService();

            ServiceBase[] ServicesToRun;
            ServicesToRun = new ServiceBase[]
            {
                MonitorService
            };
            ServiceBase.Run(ServicesToRun);
        }