WebBrowser让DocumentCompleted事件执行完毕后再往下执行

Q:WebBrowser如何让DocumentCompleted事件执行完毕后再往下执行?

A:使用信号量,等待一下

System.Threading.AutoResetEventobj = new System.Threading.AutoResetEvent( false );
void webBrowser1_DocumentCompleted( object sender,WebBrowserDocumentCompletedEventArgse)
... {
obj.Set();
}


private void button1_Click( object sender,EventArgse)
... {
this .webBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser1_DocumentCompleted);
this .webBrowser1.Navigate( " www.sina.com.cn " );
obj.Reset();
while (obj.WaitOne( 10 , false ) == false ) ... {Application.DoEvents();}
MessageBox.Show(
"" );
}

你可能感兴趣的:(WebBrowser)