Skip to content

Commit bafde73

Browse files
authored
WPF/OffScreen - Avoid ObjectDisposedException when browser is already disposed (#4941)
1 parent 6acdcc3 commit bafde73

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

CefSharp.OffScreen/ChromiumWebBrowser.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,10 @@ protected virtual void Dispose(bool disposing)
291291
//Stop rendering immediately so later on when we dispose of the
292292
//RenderHandler no further OnPaint calls take place
293293
//Check browser not null as it's possible to call Dispose before it's created
294-
browser?.GetHost().WasHidden(true);
294+
if (browser?.IsDisposed == false)
295+
{
296+
browser?.GetHost().WasHidden(true);
297+
}
295298

296299
// Don't reference event listeners any longer:
297300
AddressChanged = null;

CefSharp.Wpf/ChromiumWebBrowser.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,10 @@ private void InternalDispose(bool disposing)
671671
//Stop rendering immediately so later on when we dispose of the
672672
//RenderHandler no further OnPaint calls take place
673673
//Check browser not null as it's possible to call Dispose before it's created
674-
browser?.GetHost().WasHidden(true);
674+
if (browser?.IsDisposed == false)
675+
{
676+
browser?.GetHost().WasHidden(true);
677+
}
675678

676679
UiThreadRunAsync(() =>
677680
{

0 commit comments

Comments
 (0)