Reputation: 41
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.
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.
Thank you in advance.
Upvotes: 1
Views: 85
Reputation: 1969
As far as I know, Application.Exit() close all tasks.
Try with:
Enviroment.Exit()
Upvotes: 1