Detect Changes in Network Connectivity
Some times you will need a mechanism to check whether changes to network occurring during running your application.
So as a solution for this you can add handlers to the static NetworkAddressChanged and NetworkAvailabilityChanged events implemented by theSystem.Net.NetworkInformation.NetworkChange class.
Souce Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.NetworkInformation;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
// Add the handlers to the NetworkChange events.
NetworkChange.NetworkAvailabilityChanged +=
NetworkAvailabilityChanged;
NetworkChange.NetworkAddressChanged +=
NetworkAddressChanged;
Console.ReadLine();
}
// Declare a method to handle NetworkAvailabilityChanged events.
private static void NetworkAvailabilityChanged(
object sender, NetworkAvailabilityEventArgs e)
{
// Report whether the network is now available or unavailable.
if (e.IsAvailable)
{
Console.WriteLine("Network Available");
}
else
{
Console.WriteLine("Network Unavailable");
}
}
// Declare a method to handle NetworkAdressChanged events.
private static void NetworkAddressChanged(object sender, EventArgs e)
{
Console.WriteLine("Current IP Addresses:");
// Iterate through the interfaces and display information.
foreach (NetworkInterface ni in
NetworkInterface.GetAllNetworkInterfaces())
{
foreach (UnicastIPAddressInformation addr
in ni.GetIPProperties().UnicastAddresses)
{
Console.WriteLine(" - {0} (lease expires {1})",
addr.Address, DateTime.Now +
new TimeSpan(0, 0, (int)addr.DhcpLeaseLifetime));
}
}
}
}
}
http://www.codeproject.com/Articles/206720/Simple-Network-Status-Monitor-Example
Detect Changes in Network Connectivity的更多相关文章
- ionic_ Network connectivity error occurred, are you offline?
错误如下: HenHouse admin$ ionic cordova build ios --prod > ionic integrations enable cordova ✖ Downlo ...
- Coursera Algorithms week1 查并集 练习测验:1 Social network connectivity
题目原文描述: Given a social network containing. n members and a log file containing m timestamps at which ...
- [转]Peer-to-Peer Communication Across Network Address Translators
Peer-to-Peer Communication Across Network Address Translators Bryan Ford Massachusetts Institute of ...
- Android开发训练之第五章——Building Apps with Connectivity & the Cloud
Building Apps with Connectivity & the Cloud These classes teach you how to connect your app to t ...
- RabbitMQ Network Partitions
Clustering and Network Partitions RabbitMQ clusters do not tolerate network partitions well. If you ...
- Managing Network Usage
This lesson describes how to write applications that have fine-grained control over their usage of n ...
- Configure a bridged network interface for KVM using RHEL 5.4 or later?
environment Red Hat Enterprise Linux 5.4 or later Red Hat Enterprise Linux 6.0 or later KVM virtual ...
- Simple Network Management Protocol - SNMP Tutorial
30.9 Simple Network Management Protocol Network management protocols specify communication between t ...
- How Network Load Balancing Technology Works--reference
http://technet.microsoft.com/en-us/library/cc756878(v=ws.10).aspx In this section Network Load Balan ...
随机推荐
- ubuntu安装zeromq
官网地址:http://zeromq.org/ ubuntu下zmq安装 (1)下载:wget http://download.zeromq.org/zeromq-4.1.4.tar.gz (2)解压 ...
- statistical thinking in Python EDA
Histgram直方图适合于单个变量的value分布图形 seaborn在matplotlib基础上做了更高层的抽象,方便对基础的图表绘制.也可以继续使用matplotlib直接绘图,但是调用seab ...
- 使用 CLI 创建 Azure VM 的自定义映像
自定义映像类似于应用商店映像,不同的是自定义映像的创建者是你自己. 自定义映像可用于启动配置,例如预加载应用程序.应用程序配置和其他 OS 配置. 在本教程中,你将创建自己的 Azure 虚拟机自定义 ...
- C/C++内存分区
C/C++编译的程序占用的内存分区 1.栈区(stack)— 由编译器自动分配释放 ,存放函数的参数名,局部变量的名等.其操作方式类似于数据结构中的栈. 2.堆区(heap)— 由程序员分配释放, 若 ...
- Winform 多个窗口编辑同一条数据同步的实现
场景: 一个主窗口中,可以在列表(DataGridView)里选中一条记录编辑,打开一个编辑窗口(非模态窗口),编辑窗口保存后需要刷新父窗口,由于编辑窗口是非模态窗口,如果打开了多个窗口,并且都是编辑 ...
- 记录Ubuntu14.04 LTS版本中使用Docker的过程
sudo apt-get update sudo apt-get install \ apt-transport-https \ ca-certificates \ curl \ software-p ...
- 渐变显示渐变消失的BackgroundView
渐变显示渐变消失的BackgroundView 效果如下: 源码: BackgroundView.h 与 BackgroundView.m // // BackgroundView.h // Test ...
- Spring Security自定义GrantedAuthority前缀
如果我们正使用Spring Security提供默认的基于方法的权限认证注解如下: @PreAuthorize("hasAnyRole('ADMIN', 'USER')") pub ...
- 深入理解python中的yield关键字
想必大家都看过这样的代码: 上面的这段代码会计算0-9的平方并打印出来. 那么问题来了,这段代码和我们要说的东西有什么区别呢? 这里的关键字,yield,我在前面的文章里已经发过了.那么yield是什 ...
- 【1】python-正则表达式语法规范与案例
正则表达式的用法与案例分析 2018-08-24 21:26:14 [说明]:该文主要为了随后复习和使用备查,由于做了word文档笔记,所以此处博文没有怎么排版,没放代码,以插入图片为主, 一.正则表 ...