Skip to content

Commit d00f9c8

Browse files
committed
WPF/OffScreen - WaitForRenderIdleAsync possible ObjectDisposedException
- Potentially the call to the Stop/Start the Timer in the Paint event handler may result in an ObjectDisposedException as the Timer was disposed on a different thread. Resolves #4597
1 parent bb30e23 commit d00f9c8

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

CefSharp.OffScreen/ChromiumWebBrowser.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -727,8 +727,17 @@ public async Task WaitForRenderIdleAsync(int idleTimeInMs = 500, TimeSpan? timeo
727727
//Every time Paint is called we reset our timer
728728
handler = (s, args) =>
729729
{
730-
idleTimer.Stop();
731-
idleTimer.Start();
730+
try
731+
{
732+
idleTimer?.Stop();
733+
idleTimer?.Start();
734+
}
735+
catch (ObjectDisposedException)
736+
{
737+
// NOTE: When the Elapsed (or Timeout) and Paint are fire at almost exactly
738+
// the same time, the timer maybe Disposed on a different thread.
739+
// https://github.com/cefsharp/CefSharp/issues/4597
740+
}
732741
};
733742

734743
idleTimer.Start();

CefSharp.Wpf/ChromiumWebBrowser.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2711,8 +2711,17 @@ public async Task WaitForRenderIdleAsync(int idleTimeInMs = 500, TimeSpan? timeo
27112711
//Every time Paint is called we reset our timer
27122712
handler = (s, args) =>
27132713
{
2714-
idleTimer.Stop();
2715-
idleTimer.Start();
2714+
try
2715+
{
2716+
idleTimer?.Stop();
2717+
idleTimer?.Start();
2718+
}
2719+
catch (ObjectDisposedException)
2720+
{
2721+
// NOTE: When the Elapsed (or Timeout) and Paint are fire at almost exactly
2722+
// the same time, the timer maybe Disposed on a different thread.
2723+
// https://github.com/cefsharp/CefSharp/issues/4597
2724+
}
27162725
};
27172726

27182727
idleTimer.Start();

0 commit comments

Comments
 (0)