Beispiel #1
0
 protected override void OnStop()
 {
     // TODO: Add code here to perform any tear-down necessary to stop your service.
     Program.killAll = true;
     srv.ServiceStop();
 }
Beispiel #2
0
        static void Main(string[] args)
        {
            ServiceBase[] ServicesToRun;

            String path = System.Reflection.Assembly.GetExecutingAssembly().Location;

            cfgFile       = Path.ChangeExtension(path, ".cfg");
            logMain       = Path.ChangeExtension(path, ".log");
            logNameExport = Path.Combine(Path.GetDirectoryName(path), "Sms.WriteKKM.NET.log");
            logNameImport = Path.Combine(Path.GetDirectoryName(path), "Sms.ReadKKM.NET.log");

            Load(cfgFile);

            commandTimeout = Convert.ToInt32(Program.GetValue("CommandTimeOut", "1000"));
            lSizeLogFile   = Convert.ToInt32(Program.GetValue("SizeLogFile", "104857600"));

            if (args.Length >= 2)
            {
                if ((args[0].ToLower() == "-install") || (args[0].ToLower() == "-i"))
                {
                    sms_new.SCM.CreateService(args[1]);
                    return;
                }
                else
                if ((args[0].ToLower() == "-remove") || (args[0].ToLower() == "-r"))
                {
                    sms_new.SCM.RemoveService(args[1]);
                    return;
                }
                else
                if (args.Length >= 1)
                {
                    if ((args[0].ToLower() == "-debug") || (args[0].ToLower() == "-d"))
                    {
                        string fileStop = Path.Combine(Path.GetDirectoryName(path), "Sms_stop.t-m");

                        bDebugMode = true;

                        WriteLog("");
                        WriteLog("==============================================================================");
                        WriteLog("Режим отладки сервиса...");
                        //Console.WriteLine("Режим отладки сервиса...");

                        signalHandler += HandleConsoleSignal;
                        ConsoleHelper.SetSignalHandler(signalHandler, true);

                        ServiceBody srv = new ServiceBody();
                        srv.ServiceStart(args);

                        while (!File.Exists(fileStop))
                        {
                            Thread.Sleep(200);
                        }
                        File.Delete(fileStop);
                        killAll = true;

                        srv.ServiceStop();

                        WriteLog("Режим отладки сервиса остановлен");

                        return;
                    }
                }
            }

            // More than one user Service may run within the same process. To add
            // another service to this process, change the following line to
            // create a second service object. For example,
            //
            //   ServicesToRun = new ServiceBase[] {new Service1(), new MySecondUserService()};
            //
            ServicesToRun = new ServiceBase[] { new ServiceSMS("Service1") };

            ServiceBase.Run(ServicesToRun);
        }