public void Execute() { if (this.isExecuting || !this.captureService.IsRecycleNeeded()) { return; } this.isExecuting = true; TimerUtility.RunSafeDelayedAction(() => { this.ExecuteUnsafe(); this.isExecuting = false; }, TimeSpan.FromMilliseconds(500), (error) => { this.isExecuting = false; this.logger.Error("Got fatal error during Panel recycle {0}", error.ToString()); }); }
private void Viewport_NavigationCompletedImpl(int attempts = ScreenCapturePanel.DEFAULT_CAPTURE_MAX_RETRY_ATTEMPTS) { this.logger.Verbose($"running delayed capture with settle time of {this.appConfig.DefaultPageSettleDelay}..."); // we introduce an artificial delay before processing the capture. // this is DUMB!, there's no definitive way to know if the page has "settled". TimerUtility.RunDelayedAction(() => { // note: removed && this.IsVisible() check here, maybe that is necessary? if (this.requestFocus(this)) { // delay one more tick so we give the control time to render TimerUtility.RunSafeDelayedAction(() => { this.HandleScreenCapture(); }, TimeSpan.FromMilliseconds(2000), (error) => { // HandleScreenCapture should be safe. no-op if (this.IsCaptureInProgress) { this.CleanupCaptureRun(success: false); } }); } else if (attempts > 0) { this.logger.Warn($"Panel {this.Config.PrettyName} attempting to perform screen capture, but another panel already is visible, will retry {attempts} attempts..."); // TODO: randomize the retry time? this.Viewport_NavigationCompletedImpl(attempts - 1); } else { // could not get focus or we ran out of attempts this.logger.Error($"Panel {this.Config.PrettyName} failed to get focus after {ScreenCapturePanel.DEFAULT_CAPTURE_MAX_RETRY_ATTEMPTS} attempts"); this.CleanupCaptureRun(success: false); } }, this.appConfig.DefaultPageSettleDelay); }