Connection Check Your Internet connection with C #
by Simohamed Attahri
Use C # to detect your network connection
How to check if your computer are connected to the Internet with C #. It's much more than easier that other tutorials I ' ve seen in the other sites. In deed, we ' re going to use a simple API function internetgetconnectedstate, to return a Boolean variable.
How to use C # to detect whether your computer is connected to the Internet? This is probably the easiest tutorial I've ever seen. In fact, we just use a simple internetgetconnectedstate API function, and the result is to return a Boolean type of variable.
This function takes two arguments:
This function has two parameters:
The ' The ' is ' is ' an integer used and out keyword, that's means that's after calling the function, the variable'll contain a N Interger that describes the connection state (with a modem, use of a proxy, offline mode ...). This is the must refer to www.msdn.com for more information about that.
The second one is a reserved variable that must being set to 0.
The first is the number of integers with the Out keyword, that is, after the function is called, the variable should contain an integer that describes the state of the connection (using the modem, using the proxy, offline mode). You can go to www.msdn.com to get more relevant information.
The second parameter is set to a reserved variable of zero.
In this tutorial, we'll create a class with a static function of that returns true if connected and false if not, using our PI function in the private state.
In this tutorial, we create a class with a static function that uses API functions in a private domain. Returns False if the hyphen returns true.
Check this out:
Using System;
Using System.Runtime;
Using System.Runtime.InteropServices;
public class Internetcs
{
Creating the extern function ...
[DllImport ("Wininet.dll")]
private extern static bool InternetGetConnectedState (int out Description, int reservedvalue);
Creating a function that uses API function ...
public static bool Isconnectedtointernet ()
{
int Desc;
Return InternetGetConnectedState (out Desc, 0);
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.