Ejemplo n.º 1
0
 private void InitializeTimer(double timeInterval)
 {
     if (timeInterval > 0)
     {
         ServiceTimer.Dispose();
         ServiceTimer          = new Timer();
         ServiceTimer.Enabled  = true;
         ServiceTimer.Elapsed += new ElapsedEventHandler(timer1_Tick);
         ServiceTimer.Interval = 10000;
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// The method that will be executed when the service is stopped.  This method
        /// disposes of the <see cref="ServiceTimer"/>. The <see cref="OnStop"/>
        /// abstract method will also be called if the service requires additional functionality
        /// on stopping. This method will catch and log any exceptions that occur on stopping.
        /// </summary>
        public void Stop()
        {
            try
            {
                Log.Info("Stopping periodic service.");
                if (ServiceTimer != null)
                {
                    ServiceTimer.Dispose();
                }

                OnStop();
            }
            catch (Exception ex)
            {
                Log.ErrorFormat("An error occured while stopping the service: \n{0}", ex);
            }
        }
Ejemplo n.º 3
0
 protected override void OnStop()
 {
     ServiceTimer.Enabled = false;
     ServiceTimer.Dispose();
     ServiceTimer = null;
 }