Check Your Internet Connection With C

來源:互聯網
上載者:User
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...

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.