Check Your Internet Connection With C #
By Simohamed Attahri
Use C # to check your network connection
How to check if your computer is connected to the internet with C #. it's much more easier that other tutorials I 've seen in other sites. in deed, we're re going to use a simple API function InternetGetConnectedState, to return a boolean variable.
How can I use C # to check whether your computer is connected to the Internet? This may be the simplest tutorial I have ever seen. In fact, we use a simple InternetGetConnectedState API function. The result is a boolean variable.
This function takes two arguments:
This function has two parameters:
The first one is an integer used with out keyword, that means that after calling the function, the variable will contain in an interger that describes the connection state (use of a modem, use of a proxy, offline mode ...). note that you must refer to www.msdn.com for more information about that.
The second one is a reserved variable that must be set to 0.
The first is the integer number with the out keyword. That is to say, after calling a function, the variable should contain an integer number describing the connection status (using a modem, using a proxy, or offline mode. You can go to www.msdn.com to get more information.
The second parameter is set to a reserved variable of zero.
In this tutorial, we'll create a class with a static function that returns true if connected and false if not, using our API function in private state.
In this tutorial, we create a class with static functions and use API functions in private domains. If it is connected, true is returned. Otherwise, false is returned.
Check this out:
Using System;
Using System. Runtime;
Using System. Runtime. InteropServices;
Public class InternetCS
{
// Creating the extern function...
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.