0

I am working on a offline mode for a project in C#.

A user connected to his enterprise network via vpn client at home. If internet connectivity has gone and immediately the next one minute, the particular vpn client try to reconnect. In this situation the below method GetIsNetworkAvailable() gives the internet connectivity state as True. But logically i am not connected to Internet.

Is there any way get the correct internet connectivity state when my vpn client try to reconnect.

bool isConnected = System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable();
  • 1
    I think your definition of "correct internet connectivity state" differs from the one Microsoft uses. – CodeCaster Jul 01 '13 at 15:31
  • the below method is taking 30 to 45 seconds to give the result if i am not connected to internet and my vpn client try to do reconnecting.. IPHostEntry dummy = Dns.GetHostEntry("www.google.com"); Please note i have no intention to waste any one of time. I have real problem and asking real question. Not like MSDN Forum, i can't ask my own question. Everyone top of my question and try to destroy my question :( – Selvakumar Jul 01 '13 at 16:02
  • At least it's still under a minute though... – Sam Jul 01 '13 at 16:04
  • Since i am calling this method more frequently in my application to know user offline state, my application is being unresponsive for 1 minute when user's vpn client try to reconnect when internet is not there.. This is my problem. – Selvakumar Jul 01 '13 at 16:06
  • Then use an [asynchronous](http://stackoverflow.com/questions/17406591/async-modifier-in-c-sharp) method instead. – Sam Jul 01 '13 at 16:09
  • i tried async as well and there is no big difference. – Selvakumar Jul 01 '13 at 16:12
  • Create a new property, then update the property from a separate thread. – Sam Jul 01 '13 at 16:15
  • You could try using [Dns.GetHostEntryAsync](http://msdn.microsoft.com/en-us/library/system.net.dns.gethostentryasync.aspx). – Sam Jul 01 '13 at 16:24
  • Thanks Sam. But Dns.GetHostEntryAsync will only work for .Net Framework 4.5. But my code is on .net framework 4. – Selvakumar Jul 01 '13 at 16:30
  • Your welcome. Can't you move up to 4.5? Other than that, i can't think of anything else. – Sam Jul 01 '13 at 16:36
  • If i have google's IP in my DNS cache, it won't send a DNS request, so it could return true even when i am not connected – Selvakumar Jul 01 '13 at 18:51

0 Answers0