コード例 #1
0
 private void WriteActivity(ActiveApp activity)
 {
     using (var streamWriter = File.AppendText(_logPath))
     {
         streamWriter.WriteLine(activity.ToCsv());
     }
 }
コード例 #2
0
        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);
                }
            }
        }