コード例 #1
0
        /// <summary>
        /// When implemented in a derived class, executes when a Stop command is sent to the service
        /// by the Service Control Manager (SCM). Specifies actions to take when a service stops
        /// running.
        /// </summary>
        protected override void OnStop()
        {
            // give shutdown process time to run if running
            for (int i = 0; i <= 120; i++)
            {
                if (_cdft.ProcessRunning == 0 | CDFMonitor.CloseCurrentSessionEvent.WaitOne(1000))
                {
                    //if (CDFMonitor.CloseCurrentSessionEvent.WaitOne(1000))
                    //{
                    break;

                    //}
                }
                else
                {
                    RequestAdditionalTime(1000);
                }
            }

            Debug.Print("OnStop:requesting 2 minutes shutdown from service.");
            RequestAdditionalTime(120000);
            Debug.Print("OnStop:setting sesion close event.");
            _cdft.WndMsgHandler(CDFMonitor.CtrlType.CTRL_CLOSE_EVENT);
            Debug.Print("OnStop:joining start thread.");
            _thread.Join(120000);
            Debug.Print("OnStop:calling base OnStop().");
            base.OnStop();
        }