Exemple #1
0
        public void Boot(IServiceArgs serviceArgs)
        {
            if (serviceArgs != null)
            {
                if (serviceArgs.LaunchDebugger)
                {
                    Debugger.Launch();
                }
            }

            try
            {
                _log.Log(LogCatagory.Info, "ServiceBoot starting Windows service instance.");

                // Entry point when running in console mode.
                if (Environment.UserInteractive)
                {
                    SubscribeToConsoleCancel();

                    _serviceInstance.StartInstance();

                    _log.Log(LogCatagory.Info, "Windows service instance started. Waiting for stop signal.");
                    // Wait on the stop signal of all instances of ServiceInstance. This will simulate the behaviour of ServiceBase.Run().
                    _serviceInstance.InstanceStopped.WaitOne();
                }
                // Entry point when running as a service.
                else
                {
                    var service = _serviceInstance as ServiceBase;
                    if (service == null)
                    {
                        _log.Log(LogCatagory.Warn, String.Format("Could not cast service instnace to type of ServiceBase. Instance: {0}.", _serviceInstance));
                    }

                    ServiceBase.Run(service);
                }

                _log.Log(LogCatagory.Info, "Windows service instance has stopped.");
            }
            catch (Exception e)
            {
                _log.Log(LogCatagory.Error, e, "ServiceBoot caught an unexpected exception while in Boot().");
            }
        }