public void Stop() { _stopThread.Set(); UnRegisterPowerEventHandler(); // dereference the PowerManager instance _powerManager = null; // Remove the default set of standby/resume handlers _factory.RemoveDefaultSet(); Unregister(_clientStandbyHandler); Unregister(_clientWakeupHandler); Log.Debug("PowerScheduler: Removed default set of standby/resume handlers to PowerScheduler"); SendPowerSchedulerEvent(PowerSchedulerEventType.Stopped); Log.Info("Powerscheduler: stopped"); }
public void Start(IController controller) { try { string threadname = Thread.CurrentThread.Name; if (string.IsNullOrEmpty(threadname)) Thread.CurrentThread.Name = "Powerscheduler"; } catch (Exception ex) { Log.Error("Powerscheduler: Error naming thread - {0}", ex.Message); } _controller = controller; Register(_clientStandbyHandler); Register(_clientWakeupHandler); RegisterPowerEventHandler(); Log.Debug("PowerScheduler: Registered default set of standby/resume handlers to PowerScheduler"); // Create the PowerManager that helps setting the correct thread executation state _powerManager = new PowerManager(); // Create the timer that will wakeup the system after a specific amount of time after the // system has been put into standby if (_wakeupTimer == null) { _wakeupTimer = new WaitableTimer(); _wakeupTimer.OnTimerExpired += new WaitableTimer.TimerExpiredHandler(OnWakeupTimerExpired); _wakeupTimer.OnTimerException += new WaitableTimer.TimerExceptionHandler(OnWakeupTimerException); } // Configure remoting if not already done StartRemoting(); LoadSettings(); // Create the default set of standby/resume handlers if (_factory == null) _factory = new PowerSchedulerFactory(controller); _factory.CreateDefaultSet(); SendPowerSchedulerEvent(PowerSchedulerEventType.Started); Log.Debug("PowerScheduler: Starting poll thread"); _stopThread = new ManualResetEvent(false); _pollThread = new Thread(new ThreadStart(PollThread)); _pollThread.Name = "PowerScheduler poll thread"; _pollThread.IsBackground = true; _pollThread.Priority = ThreadPriority.Normal; _pollThread.Start(); Log.Info("Powerscheduler: started"); }