-2

Possible Duplicate: Check for Internet connectivity

I've developed one Windows Forms desktop application through Visual Studio 2010 and I used C#. In this application I used the web services too which connect remotely to a database. The remote database is only accessed when the PC where this software installed have an Internet connection.

This software is used for sending a message from a PC to a mobile device. When the application will be run by the user then it will call one web service method which checks available SMS credits for that client account.

Before executing this I want to check whether Internet connectivity is available or not, when should I check this? If, when the user runs the application, an Internet connection is not available, then it opens the software interface, but it should not show available SMS credits and it should show the message "Internet connection is not available".

After that, if the user connects the PC with the network, then again the appropriate message should be shown to the user.

I'm using following code for Internet connection checking.

Computer oComputer = new Computer();
if (oComputer.Network.IsAvailable == true)
{
    showAvailableCredit();
}
else
{
    barStaticAvlbCredit.Caption = "0";
}

The showAvailableCredit() function is used for calling the available SMS credits checking web service.

Where should I write code for checking the Internet connectivity?

Community
  • 1
  • 1
Priyanka
  • 2,802
  • 14
  • 55
  • 88
  • Step one is to use the search feature. Lots of questions about this already: [Check for internet connection](http://stackoverflow.com/questions/2031824/check-for-internet-connection), [Check for internet connection constantly](http://stackoverflow.com/questions/6481957/check-for-internet-connection-constantly), [How to check if internet connectivity available or not in C#](http://stackoverflow.com/questions/3760258/how-to-check-if-internet-connectivity-available-or-not-in-c). The honey pot is here: http://stackoverflow.com/search?q=c%23+internet+connection – Cody Gray - on strike Jul 16 '11 at 08:22

1 Answers1

0

You can do ping to the remote computer just before showAvailableCredit() method call. You can find some sample code for ping in Ping Class (MSDN).

I hope this will help you to solve your problem.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Prabhakantha
  • 660
  • 5
  • 13