Beispiel #1
0
        protected override bool OnPowerEvent(PowerBroadcastStatus powerStatus)
        {
            SystemEvents.PowerModeChanged += new PowerModeChangedEventHandler((s, e) =>
            {
                switch (e.Mode)
                {
                case PowerModes.Suspend:
                    break;

                case PowerModes.Resume:
                    break;
                }
            });

            switch (powerStatus)
            {
            case PowerBroadcastStatus.Suspend:
                _numMonitors = 0;
                Logging.LogEvents("Sleep");
                _sleeping = true;
                break;

            case PowerBroadcastStatus.ResumeSuspend:
                _numMonitors = SystemStats.GetNumMonitors();
                Logging.LogEvents("Wake");
                _sleeping = false;
                break;
            }
            return(base.OnPowerEvent(powerStatus));
        }
Beispiel #2
0
        private void Update()
        {
            _numMonitors = SystemStats.GetNumMonitors();
            var energy = CorrectEnergyError(SystemStats.GetPowerUsageSinceLastQuery());

            _joulesTotal += energy.joules + GetMonitorJoulesUsed(_numMonitors);
            WriteData(energy);
        }
Beispiel #3
0
        protected override void OnSessionChange(SessionChangeDescription changeDescription)
        {
            switch (changeDescription.Reason)
            {
            case SessionChangeReason.SessionLock:
                _numMonitors = 0;
                Logging.LogEvents("Locked");
                _locked = true;
                break;

            case SessionChangeReason.SessionUnlock:
                _numMonitors = SystemStats.GetNumMonitors();
                Logging.LogEvents("Unlocked");
                _locked = false;
                break;
            }
        }
Beispiel #4
0
 protected override void OnStart(string[] args)
 {
     try
     {
         SystemStats.GetPowerUsageSinceLastQuery();
         SystemStats.GetTDP(0, ref _tdp);
         _timer = new System.Timers.Timer(Settings.Default.TimerInterval * 1000);
         Update();
         _timer.Elapsed += (s, e) =>
         {
             Update();
         };
         _timer.Start();
     }
     catch (Exception e)
     {
         Logging.Log(e.Message);
     }
 }