简体   繁体   English

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

[英]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.

相关问题 Visual Studio 2017-如何从ENVDTE获取当前运行的版本 - Visual Studio 2017 - How to get the current running edition from ENVDTE 如何在Visual Studio Xamarin中获取有关失败的构建的信息 - How to get information about a failed build in Visual Studio Xamarin Android模拟器未运行 - Visual Studio 2017 - Android Emulator Not Running - Visual Studio 2017 Visual Studio 2017 控制台未显示但正在运行 - Visual Studio 2017 Console not showing but running 如何在Visual Studio 2017中将Wikitude SDK与Xamarin组件一起使用来运行AR应用程序? - How to get a running AR app using Wikitude SDK with Xamarin Component in Visual studio 2017? 如何获取Visual Studio 2017的当前主题 - How to get current theme for Visual Studio 2017 如何在Visual Studio 2017上获取所有事件 - How to get all events on Visual Studio 2017 如何以编程方式获取有关其他解决方案的信息或进行操作? (Visual Studio,C#) - How can I programmatically get information about or manipulate another solution? (Visual Studio, C#) 在 Visual Studio 2017 中运行简单的 Hello World 时发生错误 - Errors occuring when running simple Hello World in Visual Studio 2017 旧的C#项目不在Microsoft Visual Studio 2017中运行 - Old C# projects not running in Microsoft visual studio 2017
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM