Esempio n. 1
0
        private void StartIdleMonitoring()
        {
            Console.WriteLine("Idle monitoring...");

            // TODO: will blow up if running as Debug mode within VS and try to record itself. Find out why
            var       captured = false;
            const int idleSecondElapsedToCapture = 3;

            while (true)
            {
                Thread.Sleep(50);

                if (_idleSeconds < 1)
                {
                    captured = false;
                }

                var currentTick = (uint)Environment.TickCount;
                var lastTick    = ProcessInfo.GetLastTick();

                if (lastTick == 0)                 //fails to get tick
                {
                    continue;
                }

                _seconds = (currentTick - lastTick) / 1000;                         //convert to seconds
                if (_seconds >= MinIdleSeconds)
                {
                    if (_idling == false)
                    {
                        _idling  = true;                        //tripped
                        _idledAt = _stopwatch.Elapsed.TotalSeconds;
                    }
                }
                else if (_idling)
                {
                    _idling         = false;
                    _idleContinued += _stopwatch.Elapsed.TotalSeconds - _idledAt;
                }


                if (_seconds >= MinIdleSeconds && _idling == true)
                {
                    _idleSeconds = _idleContinued + (_stopwatch.Elapsed.TotalSeconds - _idledAt);

                    if (_idleSeconds > idleSecondElapsedToCapture && !captured)
                    {
                        screenshot = CaptureCurrentWindow(_psName, _winTitle);

                        captured = true;
                    }
                }

                if (_idleDebug == 1)
                {
                    label14.Text = _idleSeconds.ToString(CultureInfo.InvariantCulture);
                    label8.Text  = _stopwatch.Elapsed.TotalSeconds.ToString(CultureInfo.InvariantCulture);
                    label22.Text = "idled at    " + _idledAt.ToString(CultureInfo.InvariantCulture);
                    label23.Text = "cont. from    " + _idleContinued.ToString(CultureInfo.InvariantCulture);
                    label25.Text = _seconds.ToString();
                }
                else
                {
                    label14.Text = ((int)_idleSeconds).ToString();
                }
            }
        }