[英]Visual Studio 2017 - Get Information about running tasks
So I have the problem, that I'm trying to perform a check whether an internet connection is available. 所以我有一个问题,我正在尝试检查互联网连接是否可用。
I am using this code snippet: 我正在使用以下代码片段:
public void tasks()
{
log.Add("LOG - Check for InternetConnection"); //log
DialogResult result = new DialogResult();
while (!InternetConnection()) //Check for Interent Connection
{
result = MessageBox.Show("No Internet Connection Detected!\nPlease Connect to Internet and Retry", "ERROR - No Internet Connection", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
if (result == DialogResult.Cancel)
{
break;
}
}
if (result == DialogResult.Cancel)
{
Application.Exit();
}
}
#region CheckInternetConnection
[DllImport("wininet.dll")]
private extern static bool InternetGetConnectedState(out int Description, int ReservedValue);
private bool InternetConnection()
{
log.Add("LOG - InternetConnection called"); //log
try
{
int Description;
return InternetGetConnectedState(out Description, 0);
}
catch //Not connected
{
log.Add("LOG - No Internet Connection"); //log
return false;
}
}
#endregion CheckInternetConnection
My problem is that, while Application.Exit()
gets executed (I checked by setting Breakpoints) the Application runs right past that line. 我的问题是,在执行
Application.Exit()
时(我通过设置断点进行检查),该应用程序恰好越过了该行。
As of my understanding, this is caused by a task running in the background. 据我了解,这是由后台运行的任务引起的。
So I want to know whether it is possible to get information about the tasks running... 所以我想知道是否有可能获得有关正在运行的任务的信息...
As you may probably know by now I am using Visual Studio 2017 and have a Windows Forms Application. 您可能现在知道,我正在使用Visual Studio 2017,并且拥有Windows窗体应用程序。
Thank you in advance. 先感谢您。
As far as I know, Application.Exit() close all tasks. 据我所知,Application.Exit()关闭所有任务。
Try with: 尝试:
Enviroment.Exit()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.