`
javasogo
  • 浏览: 1833980 次
  • 性别: Icon_minigender_1
  • 来自: 北京
文章分类
社区版块
存档分类
最新评论

Check Your Internet Connection With C#

 
阅读更多

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 ) ;

}

}

分享到:
评论

相关推荐

    demo.launch(share=True) Please check your internet connection

    This share link expires in 72 hours. For free permanent hosting and GPU upgrades, run `gradio deploy` from the terminal in the working directory to deploy to Hugging Face Spaces ...

    yarn Retrying… info There appears to be trouble with your network connection.

    Vue CLI v4.2.2 Failed to check for updates :sparkles: Creating project in /home/syw/demo

    windows 运行gclient下载webrtc所需的Windows .NET Framework 4.组件

    Failed to download the file, check your network connection, 设置“SecurityProto col”时发生异常:“由于枚举值无效,无法将空值转换为类型“System.Net.SecurityProt ocolType”。请指定以下枚举值之一,然后重...

    c# treeview 的check用法

    在.NET Framework中,C#语言提供了丰富的控件库,其中包括TreeView控件,它常用于构建层级结构的数据展示,如文件系统、组织结构等。在处理`TreeView`时,`Checkboxes`功能允许用户通过交互式勾选来选择或取消选择...

    WITH CHECK OPTION的用法

    在数据库管理领域,尤其是SQL语言的应用中,"WITH CHECK OPTION"是一个重要的概念,它主要用于视图的定义中,以限制通过视图进行的数据修改操作。本文将深入探讨WITH CHECK OPTION的用法及其背后的原理,帮助读者更...

    Check-your-network-connection-status.zip_判断网络

    "Check-your-network-connection-status.zip_判断网络"这个压缩包提供了一种方法来实时检查计算机的网络连接状态,帮助我们及时发现并解决问题。以下是对这个主题的详细阐述: 首先,我们需要理解网络连接的基本...

    UNIX下几种常见系统故障和解决办法

    解决这些问题所使用的工具主要是安装好系统时创建的应急系统启动盘,关于应急盘的做法,有很多文章都有介绍,可以参见《中国金融电脑》2001年第10期《unix系统超级用户密码丢失的处理办法》中的有关介绍。...

    C#完美演示Radio和Check控件的使用方法

    在C#编程中,Radio和Check控件是两种常见的用户界面元素,用于收集用户的输入信息。本教程将详细讲解如何在Visual C#环境下有效利用这两种控件,为初学者提供全面的理解。 首先,Radio(单选按钮)控件主要用于提供...

    check your english vocabulary for toefl

    留学托福考试考前自测词汇,绝对推荐!!!!!!!!!!!!!!!

    ORACLE_视图的_with_check_option.doc

    Oracle中的`WITH CHECK OPTION`是视图创建时的一个重要特性,用于限制对视图的数据修改操作,确保修改后的数据仍然符合视图的定义条件。这个选项使得视图不仅仅是查询的工具,也成为了一种数据安全控制手段,防止...

    frpc-linux-amd64

    Please check your internet connection. This can happen if your antivirus software blocks the download of this file. You can install manually by following these steps: 1. Download this file: ...

    cpu.exe - check your cpu status

    This tool helps you to check your cpu size and status

    oracle 下WITH CHECK OPTION用法

    Oracle 下 WITH CHECK OPTION 用法 WITH CHECK OPTION 是 Oracle 中的一种视图定义选项,它可以确保数据库中正在修改的数据的完整性。该选项通常用在视图定义中,以确保任何引用该视图的 INSERT 或 UPDATE 语句都...

    unigui_check_swith_css动画按钮_二

    这个主题"unigui_check_swith_css动画按钮_二"显然关注的是如何在Unigui应用中实现CSS动画效果的切换按钮,并且涉及到事件绑定。 1. **Unigui控件**: Unigui提供了丰富的用户界面控件,如按钮、复选框等,允许...

    EAN-13 Barcodes with C#

    ### EAN-13条形码与C#编程 #### 概述 本文将详细介绍如何使用C#语言创建EAN-13条形码。EAN-13(European Article Numbering-13)是一种广泛使用的条形码标准,特别适用于零售商品。它由13个数字组成,用于唯一标识...

    AndroidStudio插件配置

    解决Mac版AndroidStudio中marketplace plugins are not loaded问题,具体步骤请参考https://www.jianshu.com/p/e9187c176141。

    unigui_check_swith简单动画按钮

    在本文中,我们将深入探讨Unigui框架中的`check_swith`简单动画按钮以及如何处理未绑定的`check`事件。Unigui是一款基于VCL(Visual Component Library)的跨平台UI开发工具,专为Delphi和C++Builder开发者设计,...

    串行通信测试工具,C#开发

    在 Visual Studio 中用 C# (csharp) .Net (dotNet) 框架编写的串行通信测试工具。帮助你轻松地使用 rs232 、rs485 / 串行 COM 端口并监控发送和接收的数据。

    frpc-windows-amd64-v0.3

    Please check your internet connection. This can happen if your antivirus software blocks the download of this file. You can install manually by following these steps: 1. Download this file: ...

Global site tag (gtag.js) - Google Analytics