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?