Load URL from txt File and load the URL in Browser Synchronous WebClient httpRequest

▼魔方 西西 提交于 2019-11-28 14:35:19

My problem is, that the URL have to load synchronous and not asynchronous

No you can't do it synchronously, but using async/await you can pretend it.

For this, You can use a method something like this (you can even write it as an extension method)

await Navigate(webBrowser1, "http://stackoverflow.com");
DoSomethingAfterNavigationCompleted();

Task Navigate(WebBrowser wb,string url)
{
    var tcs = new TaskCompletionSource<object>();
    WebBrowserDocumentCompletedEventHandler documentCompleted = null;
    documentCompleted = (o, s) =>
    {
        wb.DocumentCompleted -= documentCompleted;
        tcs.TrySetResult(null);
    };

    wb.DocumentCompleted += documentCompleted;
    wb.Navigate(url);
    return tcs.Task;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!