public bool WaitForStandardOutput(string toWatchFor, TimeSpan maxWait) { TimeSpan pollingInterval = TimeSpan.FromMilliseconds(500); int count = 0; while (!StandardOutput.Contains(toWatchFor)) { count++; Thread.Sleep(pollingInterval); if (pollingInterval.Ticks * count > maxWait.Ticks) { return(false); } } Debug.WriteLine("Actual Wait Time: " + pollingInterval.Milliseconds * count + " milliseconds"); return(true); }
private void TimerPinger() { var secondsToIndicateOfflineStatus = 7; if (PingUtility.Pinger(out string pingException)) { _isOnline = true; if (TimersOutput != null && TimersOutput.Contains("Offline")) { TimersOutput = string.Empty; } if (StandardOutput.Contains(Localization.Properties.Resources.StandardOutputNoInternetConnection)) { StandardOutput = Localization.Properties.Resources.InternetConnectionReestablished; } if (Application.Current == null) { return; } Application.Current.Dispatcher.Invoke(() => { GlowBrushColor = new SolidColorBrush(Colors.LightBlue); }); _pingerCounter = 0; HelpButtonToolTip = PingUtility.AddPingToHelpButtonToolTip(HelpButtonToolTip); } else { if (_pingerCounter >= secondsToIndicateOfflineStatus) { InformationAndExceptionOutput = pingException; _isOnline = false; TimersOutput = "Offline"; Application.Current.Dispatcher.Invoke(() => { GlowBrushColor = new SolidColorBrush(Colors.Red); }); HelpButtonToolTip = PingUtility.AddPingToHelpButtonToolTip(HelpButtonToolTip); } _pingerCounter++; } }