Exemplo n.º 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);
                    }
                }
            }
        }
Exemplo n.º 2
0
 public void TestIdle()
 {
     for (int i = 0; i < 30; i++)
     {
         Log.Debug($"Time: {SystemIdle.GetLastInputIdleTimeSpan()}");
         Thread.Sleep(1000);
     }
 }
Exemplo n.º 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);
                    }
                }
            }
        }