mirror of
https://github.com/cefsharp/CefSharp.git
synced 2026-12-05 03:32:37 +00:00
Core - ManagedCefBrowserAdapter::InitializeBrowserProcessServiceHost improve Dispose handling
As the browser is Disposed on a different Thread to OnAfterBrowserCreated is called there's possibility of an ObjectDisposedException. Instead of locking just catch and ignore the error as it's extremely rare Resolves #3437
This commit is contained in:
@@ -105,19 +105,28 @@ namespace CefSharp
|
||||
// NOTE: This was moved out of OnAfterBrowserCreated to prevent the System.ServiceModel assembly from being loaded when WCF is not enabled.
|
||||
__declspec(noinline) void ManagedCefBrowserAdapter::InitializeBrowserProcessServiceHost(IBrowser^ browser)
|
||||
{
|
||||
_browserProcessServiceHost = gcnew BrowserProcessServiceHost(_javaScriptObjectRepository, Process::GetCurrentProcess()->Id, browser->Identifier, _javascriptCallbackFactory);
|
||||
//NOTE: Attempt to solve timing issue where browser is opened and rapidly disposed. In some cases a call to Open throws
|
||||
// an exception about the process already being closed. Two relevant issues are #862 and #804.
|
||||
if (_browserProcessServiceHost->State == CommunicationState::Created)
|
||||
if (browser->IsDisposed)
|
||||
{
|
||||
try
|
||||
return;
|
||||
}
|
||||
|
||||
//As the default the browser is Disposed on a different thread to this method it's possible that
|
||||
//we arrive here after browser has started Disposing. In that case there's likely to be an exception
|
||||
//accessing the Browser and possibly the serviceHost.
|
||||
//https://github.com/cefsharp/CefSharp/issues/3437
|
||||
try
|
||||
{
|
||||
_browserProcessServiceHost = gcnew BrowserProcessServiceHost(_javaScriptObjectRepository, Process::GetCurrentProcess()->Id, browser->Identifier, _javascriptCallbackFactory);
|
||||
//NOTE: Attempt to solve timing issue where browser is opened and rapidly disposed. In some cases a call to Open throws
|
||||
// an exception about the process already being closed. Two relevant issues are #862 and #804.
|
||||
if (_browserProcessServiceHost->State == CommunicationState::Created)
|
||||
{
|
||||
_browserProcessServiceHost->Open();
|
||||
}
|
||||
catch (Exception^)
|
||||
{
|
||||
//Ignore exception as it's likely cause when the browser is closing
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception^)
|
||||
{
|
||||
//Ignore exception as it's likely cause when the browser is closing/disposed
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -663,6 +663,11 @@ namespace CefSharp.OffScreen
|
||||
/// <param name="browser">The browser.</param>
|
||||
void IWebBrowserInternal.OnAfterBrowserCreated(IBrowser browser)
|
||||
{
|
||||
if (IsDisposed || browser.IsDisposed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this.browser = browser;
|
||||
|
||||
Interlocked.Exchange(ref browserInitialized, 1);
|
||||
|
||||
@@ -607,6 +607,11 @@ namespace CefSharp.WinForms
|
||||
/// <param name="browser">The browser.</param>
|
||||
void IWebBrowserInternal.OnAfterBrowserCreated(IBrowser browser)
|
||||
{
|
||||
if(IsDisposed || browser.IsDisposed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this.browser = browser;
|
||||
Interlocked.Exchange(ref browserInitialized, 1);
|
||||
|
||||
|
||||
@@ -1103,6 +1103,11 @@ namespace CefSharp.Wpf
|
||||
/// <param name="browser">The browser.</param>
|
||||
void IWebBrowserInternal.OnAfterBrowserCreated(IBrowser browser)
|
||||
{
|
||||
if (IsDisposed || browser.IsDisposed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Interlocked.Exchange(ref browserInitialized, 1);
|
||||
this.browser = browser;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user