Best Practice: Internet Connection?
-
Hello all, I would like to know what the best practice is for testing if a program has a valid internet connection. I have a function which tells me if the program is connected or not but I would hate to have to call this everytime I need to perform some operation. What I am looking for is something like in Messenger when you lose an internet connection it notifies you. Am I limited to a timer that constantly checks for the internet connection or is there some way my app can receive a message when a connection gets unplugged or something similar. Does this make any sense? Any help is greatly appreciated. :)Thanks, Troy G
-
Hello all, I would like to know what the best practice is for testing if a program has a valid internet connection. I have a function which tells me if the program is connected or not but I would hate to have to call this everytime I need to perform some operation. What I am looking for is something like in Messenger when you lose an internet connection it notifies you. Am I limited to a timer that constantly checks for the internet connection or is there some way my app can receive a message when a connection gets unplugged or something similar. Does this make any sense? Any help is greatly appreciated. :)Thanks, Troy G
-
Yes, you have to check it in a timer or thread. Whats the problem with that? Mazy You're face to face, With the man who sold the world - David Bowie
-
Hello all, I would like to know what the best practice is for testing if a program has a valid internet connection. I have a function which tells me if the program is connected or not but I would hate to have to call this everytime I need to perform some operation. What I am looking for is something like in Messenger when you lose an internet connection it notifies you. Am I limited to a timer that constantly checks for the internet connection or is there some way my app can receive a message when a connection gets unplugged or something similar. Does this make any sense? Any help is greatly appreciated. :)Thanks, Troy G
-
Hi there I have the same problem as yours but u have at least made a function to get yr work done. I couldnt even do that ! can u plz pass a copy of that function to me? Thanks VisionTec
visiontec wrote: can u plz pass a copy of that function to me? Just P/Invoke InternetGetConnectedState[^] and call it when your
Tick
event fires from your timer. - Nick Parker
My Blog -
Hi there I have the same problem as yours but u have at least made a function to get yr work done. I couldnt even do that ! can u plz pass a copy of that function to me? Thanks VisionTec
This is what I use, there are a bunch of them... //Creating the extern function... [DllImport("wininet.dll")] private extern static bool InternetGetConnectedState(out int Description, int ReservedValue); //Creating a function that uses the API function... public static bool IsConnectedToInternet() { int Desc ; return InternetGetConnectedState(out Desc, 0); }