Check your internet connection with c #

xiaoxiao2021-03-06  43

Check your internet connection with c # by Simohamed Attahri

Detey your network connection with C #

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 going to use a simple API function InternetGetConnectedState, to return a boolean variable.

How to use C # to detect if your computer is connected to the internet? This maybe I have seen the easiest tutorial. In fact, we use a simple InternetGetConnectedState API function that returns a Boolean type variable.

This function take 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 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 an integer of the OUT keyword, that is to say, the variable should contain an integer that describes the connection status (using the modem, using the proxy, offline mode). You can get more information from www.msdn.com.

The second parameter is set to zero reserved variables.

In this Tutorial, We'll Create a class with a static function That Returns True if connecture and false in, using our api function in private stat.

In this tutorial, we build a class with static functions and use the API function in the private domain. Returns true if it is connected. Otherwise, returning false.

Check this Out:

Using system.runtime; using system.Runtime.InteropServices;

Public class internetcs {

// Creating The Extern Function ... [DLLIMPORT ("Wininet.dll")] Private Extern Static Bool InternetGetConnectedState (int out design, int reserved ";

// Creating a Function That Uses the API Function ... public static bool isconnectedtidtointernet () {

INT DESC; RETURN INTERNETGETCONNECTEDSTATE (OUT DESC, 0);

}

}

转载请注明原文地址:https://www.9cbs.com/read-70188.html

New Post(0)