예제 #1
0
        public void RunService()
        {
            log.Trace(() => $"Going to run a service of type {service.GetType().FullName}");

            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
            AppDomain.CurrentDomain.DomainUnload       += CurrentDomain_DomainUnload;

            log.Trace(() => $"Registered Unhandled Exception Event");
            handle = new AutoResetEvent(false);

            Console.CancelKeyPress += Console_CancelKeyPress;


            service.ServiceFailed += Service_ServiceFailed;
            service.RunService();


            Console.WriteLine("Application Running. Use Cancel Keys (normally Ctrl+C) to close");

            log.Info("Service Started, about to block main thread");

            handle.WaitOne();
            log.Info("Main Thread Resumed to Shutdown");
            service.Shutdown();
            log.Info("Service Shutdown. Goodbye!");
        }