Beispiel #1
0
        protected override void OnStop()
        {
            try
            {
                string eventLogSource = "PC2CW Service";
                if (!EventLog.SourceExists(eventLogSource))
                {
                    EventLog.CreateEventSource(eventLogSource, "Application");
                }

                if (manager != null)
                {
                    EventLog.WriteEntry(eventLogSource, "Stopping CounterManager...", EventLogEntryType.Information);
                    manager.Stop();
                    EventLog.WriteEntry(eventLogSource, "CounterManager stopped.", EventLogEntryType.Information);
                }
                EventLog.WriteEntry(eventLogSource, "Aborting service thread...", EventLogEntryType.Information);
                serviceThread.Abort();
                EventLog.WriteEntry(eventLogSource, "Service thread aborted (last action in OnStop() )", EventLogEntryType.Information);
            }
            catch (Exception ex)
            {
                //todo: log eception stopping
                string eventLogSource = "PC2CW Service";
                if (!EventLog.SourceExists(eventLogSource))
                {
                    EventLog.CreateEventSource(eventLogSource, "Application");
                }

                EventLog.WriteEntry(eventLogSource, "Error stopping: " + ex.Message, EventLogEntryType.Error);
            }
        }