/// <summary> /// When implemented in a derived class, executes when a Start command is sent to the service by the Service Control Manager (SCM) or when the operating system starts (for a service that starts automatically). Specifies actions to take when the service starts. /// </summary> /// <param name="args">Data passed by the start command.</param> protected override void OnStart(string[] args) { try { // Subscribe to the AppDomain UnhandledException handler to allow us // to perform any cleanup and logging before stopping the service AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); // Set the ConcurrencyLevel for the ImageProcessingEngine ImageProcessingEngine.ConcurrencyLevel = Settings.ConcurrencyLevel; // Create an instance of ImapCollector for downloading of mail messages if (Program.EnableCollect) { collector = new ImapCollector(); } // Create an instance of EmailMonitor for processing of downloaded emails if (Program.EnableProcess) { monitor = new EmailMonitor(); } // Log that we have started successfully ConfigLogger.Instance.LogInfo(String.Format("{0} Started.", GetServiceName())); } catch (Exception e) { ConfigLogger.Instance.LogFatal(e); throw; } }
/// <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() { if (collector != null) { collector.Dispose(); collector = null; } if (monitor != null) { monitor.Dispose(); monitor = null; } EmailConverter.WaitOnComplete(); ImageProcessingEngine.Complete(); ConfigLogger.Instance.LogInfo(String.Format("{0} Stopped.", GetServiceName())); }