示例#1
0
        protected override void OnStart(string[] args)
        {
            _logger.Info("Starting service");

            // Update the service state to Start Pending.
            ServiceStatus serviceStatus = new ServiceStatus();

            serviceStatus.dwCurrentState = ServiceState.SERVICE_START_PENDING;
            serviceStatus.dwWaitHint     = 100000;
            SetServiceStatus(this.ServiceHandle, ref serviceStatus);

            try
            {
                mgr = new Manager();
                mgr.Initialize();

                // Update the service state to Running.
                serviceStatus.dwCurrentState = ServiceState.SERVICE_RUNNING;
                SetServiceStatus(this.ServiceHandle, ref serviceStatus);
            }
            catch (Exception e)
            {
                _logger.FatalException("Service failed to start", e);

                mgr.Stop();

                // Stop the service
                ServiceController service = new ServiceController(SERVICE_NAME);
                service.Stop();
            }
        }
示例#2
0
        static void Main(string[] args)
        {
            bool consoleMode = false;

            SqlWristbandSvc service;

            // Parse arguments
            if (args.Length > 0)
            {
                for (int i = 0; i < args.Length; i++)
                {
                    switch (args[i].ToLower())
                    {
                    case "/install":
                        service = new SqlWristbandSvc();
                        service.InstallService();
                        service.Dispose();
                        return;

                    case "/uninstall":
                        service = new SqlWristbandSvc();
                        service.UninstallService();
                        service.Dispose();
                        return;

                    case "/console":
                        consoleMode = true;
                        break;
                    }
                }
            }

            // Launch the service in either console or Windows service mode
            if (consoleMode)
            {
                Manager manager = new Manager();

                Console.WriteLine("Starting worker threads...");
                manager.Initialize();
                Console.WriteLine("<Press any key to exit...>");
                Console.Read();

                manager.Stop();
            }
            else
            {
                service = new SqlWristbandSvc();
                var servicesToRun = new ServiceBase[] { service };
                ServiceBase.Run(servicesToRun);
            }
        } // end of Main method
示例#3
0
        static void Main(string[] args)
        {
            bool consoleMode = false;

            SqlWristbandSvc service;

            // Parse arguments
            if (args.Length > 0)
            {
                for (int i = 0; i < args.Length; i++)
                {
                    switch (args[i].ToLower())
                    {
                        case "/install":
                            service = new SqlWristbandSvc();
                            service.InstallService();
                            service.Dispose();
                            return;
                        case "/uninstall":
                            service = new SqlWristbandSvc();
                            service.UninstallService();
                            service.Dispose();
                            return;
                        case "/console":
                            consoleMode = true;
                            break;
                    }
                }
            }

            // Launch the service in either console or Windows service mode
            if (consoleMode)
            {
                Manager manager = new Manager();

                Console.WriteLine("Starting worker threads...");
                manager.Initialize();
                Console.WriteLine("<Press any key to exit...>");
                Console.Read();

                manager.Stop();
            }
            else
            {
                service = new SqlWristbandSvc();
                var servicesToRun = new ServiceBase[] { service };
                ServiceBase.Run(servicesToRun);
            }
        }
        protected override void OnStart(string[] args)
        {
            _logger.Info("Starting service");

            // Update the service state to Start Pending.
            ServiceStatus serviceStatus = new ServiceStatus();
            serviceStatus.dwCurrentState = ServiceState.SERVICE_START_PENDING;
            serviceStatus.dwWaitHint = 100000;
            SetServiceStatus(this.ServiceHandle, ref serviceStatus);

            try
            {
                mgr = new Manager();
                mgr.Initialize();

                // Update the service state to Running.
                serviceStatus.dwCurrentState = ServiceState.SERVICE_RUNNING;
                SetServiceStatus(this.ServiceHandle, ref serviceStatus);
            }
            catch (Exception e)
            {
                _logger.FatalException("Service failed to start", e);

                mgr.Stop();

                // Stop the service
                ServiceController service = new ServiceController(SERVICE_NAME);
                service.Stop();
            }
        }