|
-
Sep 22nd, 2007, 11:00 PM
#1
Thread Starter
Hyperactive Member
[1.0/1.1] Detecting if there is an Internet Connection
Hi. I usually detect if there is an internet connection by pinging a popular site like yahoo or google. However I was wondering if there is a neater way to determine if there is an internet connection, similar to MSN.
From what i've noticed with msn is that as soon as an Internet connection is made active, msn signs in. That rules out some kind of thread, looks more like an event handler or something of that sort.
Does anyone knows of a neat way to detect if an Internet connection is active?
Jennifer.
-
Sep 23rd, 2007, 05:43 AM
#2
Re: [1.0/1.1] Detecting if there is an Internet Connection
You can use the InternetGetConnectedState API to determine if an internet connection is active.
But using .NET you can use System.Net.NetworkInformation.NetworkChange method or there is some other SystemInformation.Network method.
SystemInformation.Network Method:
C# Code:
bool ConState = SystemInformation.Network;
if (ConState)
{
MessageBox.Show ("Connected");
}
else
{
MessageBox.Show ("No connection");
}
Last edited by Paul M; Sep 23rd, 2007 at 05:49 AM.
-
Sep 25th, 2007, 02:37 AM
#3
Re: [1.0/1.1] Detecting if there is an Internet Connection
I believe MSN periodically attempts to ping an MSN server, although I might be wrong. I usually treat connectivity issues by assuming a connection is present and trapping an error in the case that it is not.
-
Sep 26th, 2007, 10:18 AM
#4
Thread Starter
Hyperactive Member
Re: [1.0/1.1] Detecting if there is an Internet Connection
Thanks hell lord, it worked.
Penegate, that's how i usually do it. However, i observed MSN and what i noticed is that if it's running in the background, not connected (since the internet connection) is down, and I start the internet connection, as soon as the internet connects, it detects it and signs in. It was just what I observed which made me suspect that its doing more that detecting if the connection exists at periodic intervals. I could be wrong, but its what i observed.
Thank you very much for you help.
Jennifer.
-
Sep 26th, 2007, 01:29 PM
#5
Addicted Member
Re: [1.0/1.1] Detecting if there is an Internet Connection
Be carefule with SystemInformation.Network. It detects the presence of a Network Connection...ANY Network Connection. So, if you are in a corporate environment or on a home network, the state of this property will ALWAYS be true as long as your network is up. Even if your Internet connection is down.
Steve
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|