国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

Check Your Internet Connection With C#

2024-07-21 02:18:27
字體:
來源:轉載
供稿:網友
check your internet connection with c#
by simohamed attahri

用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.

怎么用c#來檢測你的計算機是否連接到互聯網呢?這可能是我見過最簡單的教程了。其實我們就是使用一個簡單的internetgetconnectedstate api函數,結果是返回一個boolean類型的變量。

this function takes two arguments :

這個函數有兩個參數:

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.

第一個是帶有out關鍵字的整型數,也就是說在調用函數后,變量應該包含一個描述連接狀態(使用調制解調器、使用代理、離線模式)的整型數。你可以到www.msdn.com獲取更多相關信息。

第二個參數設置為零的保留變量。

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.

在這篇教程中,我們建立一個有著靜態函數的類,在私有域使用api函數。如果連通則返回true否則返回false。

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 the api function...
public static bool isconnectedtointernet( )
{

int desc ;
return internetgetconnectedstate( out desc, 0 ) ;

}

}

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 秀山| 昌图县| 中阳县| 绥江县| 上犹县| 台北市| 峨山| 永州市| 建瓯市| 达拉特旗| 时尚| 和政县| 马鞍山市| 额济纳旗| 兴隆县| 志丹县| 徐州市| 五华县| 凤山市| 阜平县| 玛沁县| 双桥区| 乐至县| 酉阳| 乐业县| 石棉县| 陵水| 漾濞| 全椒县| 东安县| 民勤县| 通城县| 延安市| 淮南市| 象山县| 隆安县| 金溪县| 镇赉县| 临高县| 炉霍县| 增城市|