コード例 #1
0
        private void CheckIdleBeforeRestart(object sender, EventArgs e)
        {
            TimeSpan timeSinceCheck = DateTime.UtcNow - lastIdleCheck;
            bool     wasSleeping    = false;

            if (timeSinceCheck > IdleTimerInterval + TimeSpan.FromMinutes(1))
            {
                // The timer did not tick within the expected timeout, thus computer was probably sleeping.
                Log.Info($"Idle timer timeout, was: {timeSinceCheck}");
                wasSleeping = true;
            }

            lastIdleCheck = DateTime.UtcNow;

            TimeSpan idleTime = SystemIdle.GetLastInputIdleTimeSpan();

            if (wasSleeping || idleTime > IdleTimeBeforeRestarting)
            {
                if (IsNewVersionInstalled())
                {
                    if (startInstanceService.StartInstance(modelMetadata.ModelFilePath))
                    {
                        // Newer version is started, close this instance
                        Application.Current.Shutdown(0);
                    }
                }
            }
        }
コード例 #2
0
 public void TestIdle()
 {
     for (int i = 0; i < 30; i++)
     {
         Log.Debug($"Time: {SystemIdle.GetLastInputIdleTimeSpan()}");
         Thread.Sleep(1000);
     }
 }
コード例 #3
0
        void CheckIdleBeforeRestart(object sender, EventArgs e)
        {
            TimeSpan idleTime = SystemIdle.GetLastInputIdleTimeSpan();

            if (idleTime > IdleTimeBeforeRestarting)
            {
                Track.Info($"Idle time {idleTime}, trigger restart if newer is installed");
                idleTimer.Stop();

                if (IsNewVersionInstalled())
                {
                    if (startInstanceService.StartInstance(workingFolder))
                    {
                        // Newer version is started, close this instance
                        Application.Current.Shutdown(0);
                    }
                }
            }
        }
コード例 #4
0
        private void RefreshIdleTime()
        {
            int lastIdleTimeSeconds = IdleTimeSeconds;

            IdleTimeSeconds = WindowsAPI.SystemIdleSeconds();
            if (IdleTimeoutSeconds <= 0)
            {
                return;
            }
            IdleTimeChange change = new IdleTimeChange(IdleTimeSeconds, IdleTimeoutSeconds);

            SystemActivity?.Invoke(this, change);

            if (IdleTimeSeconds < lastIdleTimeSeconds && _eventFired)
            {
                SystemIdle?.Invoke(this, new IdleChange(false));
                _eventFired = false;
            }
            else if ((IdleTimeSeconds > lastIdleTimeSeconds) && (IdleTimeSeconds >= IdleTimeoutSeconds) && !_eventFired)
            {
                SystemIdle?.Invoke(this, new IdleChange(true));
                _eventFired = true;
            }
        }