コード例 #1
0
ファイル: TerminalSSH.cs プロジェクト: EHerzog76/THB-Terminal
        /// <summary>
        /// Waits for changed screen: This method here resets
        /// the flag of the virtual screen and afterwards waits for
        /// changes.
        /// <p>
        /// This means the method detects changes after the call
        /// of the method, NOT prior.
        /// </p>
        /// <p>
        /// To reset the flag only use <code>WaitForChangedScreen(0)</code>.
        /// </p>
        /// </summary>
        /// <param name="timeoutSeconds">timeout [s]</param>
        /// <remarks>
        /// The property ChangedScreen of the virtual screen is
        /// reset after each call of Hardcopy(). It is also false directly
        /// after the initialization.
        /// </remarks>
        /// <returns>changed screen</returns>
        public bool WaitForChangedScreen(int timeoutSeconds)
        {
            // 1st check
            if (_virtualScreen == null || timeoutSeconds < 0)
            {
                return(false);
            }

            // reset flag: This has been added after the feedback of Mark
            if (_virtualScreen.ChangedScreen)
            {
                _virtualScreen.Hardcopy(false);
            }

            // Only reset
            if (timeoutSeconds <= 0)
            {
                return(false);
            }

            // wait for changes, the goal is to test at TRAILS times, if not timing out before
            int      sleepTimeMs = this.GetWaitSleepTimeMs(timeoutSeconds);
            DateTime endTime     = this.TimeoutAbsoluteTime(timeoutSeconds);

            do // run at least once
            {
                lock (_virtualScreen)
                {
                    if (_virtualScreen.ChangedScreen)
                    {
                        return(true);
                    }
                }
                Thread.Sleep(sleepTimeMs);
            } while (DateTime.Now <= endTime);
            return(false);
        } // WaitForChangedScreen