コード例 #1
0
 public void StartRecordingWith(AppUsageStartReason reason)
 {
     lock (_appUsageLock)
     {
         _recording        = true;
         _prevPath         = GetForegroundWindowPath();
         _prevFgChangeTime = DateTime.Now;
         _startReason      = reason;
     }
 }
コード例 #2
0
        private void RecordForegroundAppUsage(string path, DateTime endTime)
        {
            //Sometimes the duration is negative, but only by a few nanoseconds.
            //It is mostly harmless, but the charts considers them as having larger duration than other durations
            if (!_recording || endTime < _prevFgChangeTime)
            {
                return;
            }
            _prev = ForegroundAppUsage(_prevFgChangeTime, endTime, _prevPath);
            ForegroundAppUsageObtained(this,
                                       new ForegroundAppSwitchEventArgs(_prev, path == null ? null : new App {
                Path = path
            }));
            _prevFgChangeTime = endTime;
            _prevPath         = path;

            //reset
            _startReason = AppUsageStartReason.Switch;
            _endReason   = AppUsageEndReason.Switch;
        }