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

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