c# wpf: wait for webbrowser to load the page
<p>I have a wpf program where i want to add a WebBrowser control</p>

<p>I search how to check if the WebBrowser loaded the page successfully or not and here is the code:</p>

<pre><code>private async Task PageLoad(int TimeOut)
{
    TaskCompletionSource&lt;bool&gt; PageLoaded = null;
    PageLoaded = new TaskCompletionSource&lt;bool&gt;();
    int TimeElapsed = 0;
    webBrowser.LoadCompleted += (s, e) =&gt;
    {
        if (webBrowser.ReadyState != webBrowser.Complete) return;
        if (webBrowser.Task.IsCompleted) return;
        PageLoaded.SetResult(true);
    };

    while (PageLoaded.Task.Status != TaskStatus.RanToCompletion)
    {
        //interval of 10 ms worked good for me
        await Task.Delay(10);
        TimeElapsed++;
        if (TimeElapsed &gt;= TimeOut * 100)
        {
            //This prevents your method or thread from waiting forever
            PageLoaded.TrySetResult(true);
        }
    }
}
</code></pre>

<p>But why it doesn't work on wpf. How do I convert it?</p>

<p>I check it and the <code>ReadyState</code> <code>Complete</code> and <code>Task.IsCompleted</code> don't have a property like that in wpf. What is the code for wpf?</p>