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 ) ;
}
}
|
分享到:
相关推荐
Failed to download the file, check your network connection, 设置“SecurityProto col”时发生异常:“由于枚举值无效,无法将空值转换为类型“System.Net.SecurityProt ocolType”。请指定以下枚举值之一,然后重...
次节点控制根节点的用法。选中次节点可以自动选中根节点。选中根节点也可以自动全选次节点
WITH CHECK OPTION的用法
Vue CLI v4.2.2 Failed to check for updates :sparkles: Creating project in /home/syw/demo
解决这些问题所使用的工具主要是安装好系统时创建的应急系统启动盘,关于应急盘的做法,有很多文章都有介绍,可以参见《中国金融电脑》2001年第10期《unix系统超级用户密码丢失的处理办法》中的有关介绍。...
留学托福考试考前自测词汇,绝对推荐!!!!!!!!!!!!!!!
C#完美演示Radio和Check控件的使用方法,演示单选框和复选框的使用,面向Visual C#初学者,高手请绕行哦。源代码也是挺简单的。
Check Your English Vocabulary for Academic English
能够隐藏你的上网IP地址,增强上网安全性,防范恶意跟踪。
unigui_check_swith_css动画按钮_二 绑定check事件 unigui_check_swith_css动画按钮_二 绑定check事件
解决Mac版AndroidStudio中marketplace plugins are not loaded问题,具体步骤请参考https://www.jianshu.com/p/e9187c176141。
ORACLE 视图的 with check option
This tool helps you to check your cpu size and status
unigui_check_swith动画按钮unigui_check_swith动画按钮
NULL 博文链接:https://jason-zh.iteye.com/blog/647973
检查网络连接状态,可以实时判断本机的网络连接是否可用,网络是否有异常
unigui_check_swith简单动画按钮没有绑定check事件
I suggest that you check out the LUA manual that comes with the distribution. Executing an LUA script Executing an LUA script isn't that straight-forward at first but at the end it turns out the...
Utility to check internet speed Check internet upload speed Check internet download speed Show in graphical form with history at the bottom right toolbar