[英]C# windows application not closing
my post is same like This ... but that post didn't solve'd my question, so my question is. 我的帖子与“ 这 ...”相同,但该帖子没有解决我的问题,所以我的问题是。
m building a win app in c#, and in that im using backgroundworkder thread
and Application.DoEvents
. m在c#中构建一个Win应用程序,然后使用
backgroundworkder thread
和Application.DoEvents
构建该应用Application.DoEvents
。 here's my code: 这是我的代码:
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();
}
}
and this loop is under BackGroundWorker_DoWork()
event, The Problem is m not able to close the form or application, ie in taskmanager my app is still running, i dn't know what is the cause, maybe Application.DoEvents
or BackGroundWorker thread
, i google'd about this issue, but i didn't get any clear idea.. i tried to close the form using this: 并且此循环处于
BackGroundWorker_DoWork()
事件下,问题无法关闭表单或应用程序,即在taskmanager中我的应用程序仍在运行,我不知道是什么原因,也许是Application.DoEvents
或BackGroundWorker thread
,我用谷歌搜索了这个问题,但是我没有一个明确的主意..我试图使用以下方法关闭表单:
//Application.Exit();
//mainmdiForm.Dispose();
//mainmdiForm.Close();
//backGroundWorker.CancelAsync();
but no success. 但没有成功。 And one more thing while searchin' about this issue on google,, i got many results sayin'
Application.DoEvents()
is an EVIL, m curious why is that so ? 当在Google上搜索有关此问题的另一件事时,我在
Application.DoEvents()
发现了很多结果,这是一种错误,我很好奇为什么会这样?
while trying to close the app set the BackgroundWorker.CancelAsync()
method. 在尝试关闭应用程序时,请设置
BackgroundWorker.CancelAsync()
方法。 And in you loop check the value of the BackgroundWorker.CancellationPending
Property 然后在循环中检查
BackgroundWorker.CancellationPending
属性的值
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.