public void EndRecordingWith(AppUsageEndReason reason) { lock (_appUsageLock) { if (!_recording) { return; } _endReason = reason; RecordForegroundAppUsage(null, DateTime.Now); _recording = false; } }
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; }