On Tue, 25 Mar 2008 10:03:01 -0700, Bsmengen
<Bs******@discussions.microsoft.comwrote:
I am trying to make sure that the local connection is up. I have
presently
been using the NetworkChange.NetworkAvailabilityChanged Event for this.
Is
there a better way to do this?
Also, I want to test to see if the Internet Connection is up. I need the
Internet to be up for the Web Services I am calling. Is it better to
test
the Internet Connection through Pinging an IP Address (I presently do 3
ping
failures for it to be down) or some other way? Is there any
eventhandler out
there for checking the internet connection?
The absolute best way to detect whether your web service calls will
succeed is to try them.
You can detect network availability, but that obviously won't tell you
whether you're on the Internet or just a LAN. You also cannot reliably
know whether the network will become present at some time in the future.
For example, merely attempting network access is, in some cases,
sufficient for enabling a network that was not previously present (e.g.
dial-up network adapter).
Just because the network's not there when you look, that doesn't mean it
won't be if you try to do something with it. Likewise, just because it's
there when you do look, that doesn't mean it will be when you try to do
something with it.
Along these same lines is the Internet connectivity issue. The same thing
applies: just because it's not available when you look, that doesn't mean
it won't be when you try to use it later, and vice a versa.
So, your code must handle the error cases anyway, and it's rude to the
user to provide them with false negatives (not making an attempt to call
the web service even though it might have worked). So you should just
ignore the question of whether the network is present and connected to the
Internet, and just try to use it. If it succeeds, great...if not, tell
the user and let them deal with it. They have a _lot_ more information
than your code ever could and can much more successfully handle the issue.
Pete