protected override void OnStart(string[] args)
        {
            _stopping = false;
            _eventLog.WriteEntry("HDMI Power Manager starting...");
            File.AppendAllText("c:\\temp\\PowerMonitor.txt", DateTime.Now.ToString(CultureInfo.InvariantCulture) + " : Starting...");
            File.AppendAllLines("c:\\temp\\PowerMonitor.txt", new[] { "Can handle power event:" + CanHandlePowerEvent });
            File.AppendAllLines("c:\\temp\\PowerMonitor.txt", new[] { string.Empty });
            // Update the service state to Start Pending.
            var serviceStatus = new ServiceStatus
            {
                dwCurrentState = ServiceState.SERVICE_START_PENDING,
                dwWaitHint = 100000
            };

            SetServiceStatus(ServiceHandle, ref serviceStatus);

            RegisterForPowerNotifications();

            _myCallback = new ServiceControlHandlerEx(ServiceControlHandler);
            _thread = new Thread(WorkerThreadFunc);
            _thread.Name = "My Worker Thread";
            _thread.IsBackground = true;
            _thread.Start();



            File.AppendAllText("c:\\temp\\PowerMonitor.txt", DateTime.Now.ToString(CultureInfo.InvariantCulture) + " : _myCallback : " + _myCallback);
            File.AppendAllLines("c:\\temp\\PowerMonitor.txt", new[] { string.Empty });

            serviceStatus.dwCurrentState = ServiceState.SERVICE_RUNNING;
            SetServiceStatus(ServiceHandle, ref serviceStatus);
        }
       protected override void OnStart(string[] args)
        {
            _eventLog.WriteEntry("HDMI Power Manager starting...");
            // Update the service state to Start Pending.
           var serviceStatus = new ServiceStatus
           {
               dwCurrentState = ServiceState.SERVICE_START_PENDING,
               dwWaitHint = 100000
           };

           SetServiceStatus(ServiceHandle, ref serviceStatus);

            RegisterForPowerNotifications();

            _myCallback = new ServiceControlHandlerEx(ServiceControlHandler);
            
            serviceStatus.dwCurrentState = ServiceState.SERVICE_RUNNING;
            SetServiceStatus(ServiceHandle, ref serviceStatus);
        }
 private static extern bool SetServiceStatus(IntPtr handle, ref ServiceStatus serviceStatus);