Where to write code for Internet connectivity check in software? [duplicate]
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 c开发者_运维知识库alling the available SMS credits checking web service.
Where should I write code for checking the Internet connectivity?
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.
精彩评论