예제 #1
0
        /// <summary>
        /// Stops currently working or previously stopped service.
        /// </summary>
        /// <param name="commit">True to indicate that current operation ended successfully, false otherwise.</param>
        public void Stop(bool commit)
        {
            //the service is not started, do nothing
            if (!(this.state == ServiceState.Paused || this.state == ServiceState.Working))
            {
                return;
            }

            StateServiceStoppingEventArgs e = new StateServiceStoppingEventArgs(commit);

            this.OnStopping(e);
            if (e.Cancel)
            {
                return;
            }

            this.state = ServiceState.Stopped;
            //use the Commit member of the event arguments as the user may have changed it.
            if (e.Commit)
            {
                this.Commit();
            }
            else
            {
                this.Abort();
            }
            this.PerformStop();
            this.SetContext(null);
            this.OnStopped();
        }
예제 #2
0
        /// <summary>
        /// Notifies that a stop request has occured. Cancelable.
        /// </summary>
        /// <param name="e"></param>
        protected virtual void OnStopping(StateServiceStoppingEventArgs e)
        {
            StateServiceStoppingEventHandler eh = this.Events[StoppingEventKey] as StateServiceStoppingEventHandler;

            if (eh != null)
            {
                eh(this, e);
            }
        }