private void button1_Click_1(object sender, EventArgs e)
{
webBrowser1.Navigate("http://www.naver.com");
}
private void button2_Click_1(object sender, EventArgs e)
{
HtmlWindow wf = webBrowser1.Document.Window.Frames[0];
string s = wf.Document.Body.OuterHtml;
MessageBox.Show(s);
}
.. this does work... but i need to click two buttons. i want to make thoes together. and i wrote below codes... the error comes out on second line(nullReferenceException). it seems that await doesn`t work can anybody help??
private async void button2_Click_1(object sender, EventArgs e)
{
await Task.Run(() => webBrowser1.Navigate("http://www.naver.com"));
HtmlWindow wf = webBrowser1.Document.Window.Frames[0];
string s = wf.Document.Body.OuterHtml;
MessageBox.Show(s);
}
webBrowser1or one of its members?webBrowser1is aWebBrowsercontrol? If so, then you don't need to worry about async/await, just attach to theDocumentCompletedevent?webBrowser1.Navigate("http://www.naver.com");works butawait Task.Run(() => webBrowser1.Navigate("http://www.naver.com"));doesn't? Where does the magic variablewebBrowser1come from?webBrowser1.Navigatereturns before the page is fully loaded. You'll have to wait until theIsBusyproperty returns false to show that the page has been loaded, or use theDocumentCompletedevent (as DavidG said).