private void WriteActivity(ActiveApp activity) { using (var streamWriter = File.AppendText(_logPath)) { streamWriter.WriteLine(activity.ToCsv()); } }
private void Track() { long idleTime = WinApi.GetIdleTime(); if (idleTime > IdleThreshold) { if (_lastActivity == null || !_lastActivity.IsIdle) { var activity = new ActiveApp { DateTime = DateTime.Now.AddMilliseconds(-idleTime), IsIdle = true }; _lastActivity = activity; WriteActivity(activity); } } else { var activity = new ActiveApp { DateTime = DateTime.Now, ProcessName = WinApi.GetActiveWindowProcessName(), WindowTitle = WinApi.GetActiveWindowTitle() }; if (_lastActivity == null || _lastActivity.ProcessName != activity.ProcessName || _lastActivity.WindowTitle != activity.WindowTitle) { _lastActivity = activity; WriteActivity(activity); } } }