C# Visual Studio 2017-获取有关运行任务的信息

C# Visual Studio 2017-获取有关运行任务的信息,c#,.net,visual-studio,visual-studio-2017,C#,.net,Visual Studio,Visual Studio 2017,所以我遇到了一个问题,我正在尝试执行一个检查是否有可用的internet连接 我正在使用以下代码段: public void tasks() { log.Add("LOG - Check for InternetConnection"); //log DialogResult result = new DialogResult(); while (!InternetConnection()) //Check for Interent Connection {

所以我遇到了一个问题,我正在尝试执行一个检查是否有可用的internet连接

我正在使用以下代码段:

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
我的问题是,当执行
Application.Exit()
时(我通过设置断点进行检查),应用程序会直接运行到这一行

据我所知,这是由在后台运行的任务引起的

所以我想知道是否有可能获得有关正在运行的任务的信息

您可能知道,现在我正在使用Visual Studio 2017,并且有一个Windows窗体应用程序


提前感谢。

据我所知,Application.Exit()关闭所有任务

尝试:

Enviroment.Exit()

据我所知,Application.Exit()关闭所有任务。试试Environment.Exit()。@FelipeDeveza谢谢!它就像一个符咒!如果你能把它作为一个恰当的答案贴出来,我将非常感谢给你一些推荐。