我的职位是一样的
This
... 但那篇文章没有解决我的问题,所以我的问题是。
我在c#中构建了一个win应用程序,在该im中使用
backgroundworkder thread
和
Application.DoEvents
for(int i=0;i<gridview.rows.count-1;i++)
{
if (backThread.CancellationPending)
{
e.Cancel = true;
break;
}
string TargetFrame = "";
byte[] vPost = ASCIIEncoding.ASCII.GetBytes("_PostData");
string Header = "Content-Type: application/x-www-form-urlencoded" + "\n" + "\r";
autoWebPage.Navigate("https://xyz.com", TargetFrame, vPost, Header);
while (car == false)
{
System.Threading.Thread.Sleep(500);
Application.DoEvents();
}
}
这个循环在
BackGroundWorker_DoWork()
事件,问题是无法关闭窗体或应用程序,即在taskmanager中,我的应用程序仍在运行,我不知道是什么原因,可能
应用程序.DoEvents
或
BackGroundWorker thread
//Application.Exit();
//mainmdiForm.Dispose();
//mainmdiForm.Close();
//backGroundWorker.CancelAsync();
但没有成功。还有一件事,当我在谷歌上搜索这个问题时,我得到了很多结果
Application.DoEvents()
是个恶魔,我很好奇为什么?