From 2364b57f40e437b223a39c86fc2e686f416a5fa5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damian=20B=C3=BCchel?= Date: Tue, 11 May 2021 01:32:50 +0200 Subject: [PATCH] SEBWIN-488: Implemented pause before resetting or terminating browser in order to prevent application crashes. --- SafeExamBrowser.Browser/BrowserApplication.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/SafeExamBrowser.Browser/BrowserApplication.cs b/SafeExamBrowser.Browser/BrowserApplication.cs index 0fa519ce..f8bac541 100644 --- a/SafeExamBrowser.Browser/BrowserApplication.cs +++ b/SafeExamBrowser.Browser/BrowserApplication.cs @@ -10,6 +10,7 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; +using System.Threading; using CefSharp; using CefSharp.WinForms; using SafeExamBrowser.Applications.Contracts; @@ -119,6 +120,7 @@ namespace SafeExamBrowser.Browser public void Terminate() { logger.Info("Initiating termination..."); + AwaitReady(); foreach (var instance in instances) { @@ -145,6 +147,15 @@ namespace SafeExamBrowser.Browser } } + private void AwaitReady() + { + // We apparently need to let the browser finish any pending work before attempting to reset or terminate it, especially if the + // reset or termination is initiated automatically (e.g. by a quit URL). Otherwise, the engine will crash on some occasions, seemingly + // when it can't finish handling its events (like ChromiumWebBrowser.LoadError). + + Thread.Sleep(500); + } + private void CreateNewInstance(string url = null) { var id = ++instanceIdCounter; @@ -353,6 +364,7 @@ namespace SafeExamBrowser.Browser private void Instance_ResetRequested() { logger.Info("Attempting to reset browser..."); + AwaitReady(); foreach (var instance in instances) {