我是c#/ .net的初学者,所以请告诉我如何使用BackgroundWorker而不是Application.DoEvent。
这是我的代码:
while (webBrowser1.ReadyState!= WebBrowserReadyState.Complete)
{
Application.DoEvents(); //how to use "BackgroundWorker" here
if (webBrowser1.ReadyState == WebBrowserReadyState.Complete)
{
listBox1.Items.RemoveAt(listBox1.SelectedIndex);
listBox1.SelectedIndex = 0;
var num = listBox1.Items.Count;
string str = Convert.ToString(num);
label2.Text = str;
}
}
答案 0 :(得分:2)
您不需要BackgroundWorker。只需使用DocumentCompleted
事件。
webBrowser1.DocumentCompleted += webBrowser1_DocumentCompleted;
void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
//Do your work
}