Skip to content

Commit

Permalink
WPF - Fix Address Load being called multiple times after browser created
Browse files Browse the repository at this point in the history
  • Loading branch information
amaitland committed Oct 11, 2021
1 parent 0812ea9 commit 8bbe6a4
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion CefSharp.Wpf/ChromiumWebBrowser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ public partial class ChromiumWebBrowser : Control, IRenderWebBrowser, IWpfWebBro
/// </summary>
private string initialAddress;
/// <summary>
/// Used to stop multiple threads trying to load the initial Url multiple times.
/// If the Address property is bound after the browser is initialized
/// </summary>
private bool initialLoadCalled;
/// <summary>
/// Has the underlying Cef Browser been created (slightly different to initialized in that
/// the browser is initialized in an async fashion)
/// </summary>
Expand Down Expand Up @@ -1109,7 +1114,7 @@ void IWebBrowserInternal.SetTooltipText(string tooltipText)
SetCurrentValue(IsBrowserInitializedProperty, true);
// Only call Load if initialAddress is null and Address is not empty
if (string.IsNullOrEmpty(initialAddress) && !string.IsNullOrEmpty(Address))
if (string.IsNullOrEmpty(initialAddress) && !string.IsNullOrEmpty(Address) && !initialLoadCalled)
{
Load(Address);
}
Expand Down Expand Up @@ -2430,6 +2435,8 @@ public void Load(string url)
// or before OnApplyTemplate has been called
if (browser != null)
{
initialLoadCalled = true;

using (var frame = browser.MainFrame)
{
frame.LoadUrl(url);
Expand Down

0 comments on commit 8bbe6a4

Please sign in to comment.