示例#1
0
 public void Run(bool testMode, string[] commandLineArgs)
 {
     _testMode = testMode;
     if (testMode)
     {
         using (ServiceDebugForm form = new ServiceDebugForm())
         {
             _dbgForm            = form;
             form.Text           = WinServiceName;
             form.SupportsResume = base.CanPauseAndContinue;
             form.Stop          += debugStopHandler;
             form.Suspend       += debugSuspendHandler;
             _logger.Info("Service '{0}' is about to start in TEST mode", WinServiceName);
             form.ShowState(_stateMachine.StartState);
             try {
                 form.Show();
                 OnStart(commandLineArgs);
                 form.Visible = false;
                 form.ShowDialog();
             }
             finally {
                 form.Suspend -= debugSuspendHandler;
                 form.Stop    -= debugStopHandler;
                 _dbgForm      = null;
             }
             _logger.Info("Service '{0}' has been started in TEST mode", WinServiceName);
         }
     }
     else
     {
         _logger.Info("Service '{0}' is about to start in PRODUCTION mode", WinServiceName);
         ServiceBase.Run(this);
         _logger.Info("Service '{0}': production mode has been stopped", WinServiceName);
     }
 }
示例#2
0
        void stateChangingHndl(object sender, RuntimeServiceState state)
        {
            ServiceDebugForm form = _dbgForm;

            if (form != null)
            {
                form.ShowState(state);
            }
        }
示例#3
0
        void stateChangedHandler(object sender, RuntimeServiceState oldState, RuntimeServiceState newState, Exception ex)
        {
            ServiceDebugForm form = _dbgForm;

            if (form != null)
            {
                if (ex == null)
                {
                    form.ShowState(newState);
                }
                else
                {
                    form.ShowStateFailure(oldState, newState, ex);
                }
            }
        }