Example #1
0
        protected override void OnStop()
        {
            eventLog.WriteEntry("Stopping the service", EventLogEntryType.Information);

            try {
                if (service != null)
                {
                    service.Stop();
                    service.Dispose();
                    service = null;
                }

                eventLog.WriteEntry("Service successfully stopped");
            } catch (Exception e) {
                eventLog.WriteEntry("Error while stopping the service: " + e.Message, EventLogEntryType.Error);
                ExitCode = 1;
                throw;
            }
        }
Example #2
0
        private static bool ConsoleCtrlCheck(CtrlTypes ctrlType)
        {
            try {
                if (service != null)
                {
                    service.Stop();
                    service = null;
                    waitHandle.Set();
                }
            } catch (Exception e) {
                Console.Error.WriteLine("An error occurred while closing: " + e.Message);
                return(false);
            }

            return(true);
        }