Kalint Posted August 13, 2009 Share Posted August 13, 2009 I'm working on a new project and I'm also entering new waters. For my app I need a simple internet presence detection notification in my status bar. How would I do If internet available= Yes, else= no? Thx Link to comment Share on other sites More sharing options...
0 the_architect Posted August 13, 2009 Share Posted August 13, 2009 Use the API InternetGetConnectedState (http://msdn.microsoft.com/en-us/library/aa384702(VS.85).aspx) or a less reliable method would be to try and either ping or open a particular website and see if it works. :) Link to comment Share on other sites More sharing options...
0 Antaris Veteran Posted August 13, 2009 Veteran Share Posted August 13, 2009 You need to put a wrapper function around a WININET API call: [DllImport("wininet.dll")] private extern static bool InternetGetConnectedState(out int connectionDescription, int reservedValue); public static bool IsConnected() { int connectionDescription = 0; return InternetGetConnectedState(out connectionDescription, 0); } Source: http://weblogs.asp.net/wim/archive/2004/07/12/180608.aspx Link to comment Share on other sites More sharing options...
0 Guest Posted August 15, 2009 Share Posted August 15, 2009 or a less reliable method would be to try and either ping or open a particular website and see if it works. :) I'm guessing this is the less reliable method you are talking about... public Boolean check_Availability() { try { TcpClient tcp_Client = new TcpClient("www.google.com", 80); tcp_Client.Close(); return true; } catch (Exception) { return false; } } Link to comment Share on other sites More sharing options...
0 the_architect Posted August 16, 2009 Share Posted August 16, 2009 I'm guessing this is the less reliable method you are talking about... public Boolean check_Availability() { try { TcpClient tcp_Client = new TcpClient("www.google.com", 80); tcp_Client.Close(); return true; } catch (Exception) { return false; } } Yep :) Which method did you end up using Kalint? Link to comment Share on other sites More sharing options...
0 Kalint Posted August 17, 2009 Author Share Posted August 17, 2009 Yep :) Which method did you end up using Kalint? Yeah I'm still doing research and prototyping for this project. I'll post back once I start coding. Link to comment Share on other sites More sharing options...
0 wrack Posted August 17, 2009 Share Posted August 17, 2009 I prefer to use using System.Runtime.InteropServices; [DllImport("wininet.dll")] private extern static bool InternetGetConnectedState( out int Description, int ReservedValue ); public static bool IsInternetAvailable() { if (System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable()) { int nDescription; return InternetGetConnectedState(out nDescription, 0); } return false; } Link to comment Share on other sites More sharing options...
Question
Kalint
I'm working on a new project and I'm also entering new waters.
For my app I need a simple internet presence detection notification in my status bar.
How would I do If internet available= Yes, else= no?
Thx
Link to comment
Share on other sites
6 answers to this question
Recommended Posts