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 ...
随机推荐
- Beautifulsoup模块安装之pip命令
1.在python引用 BeautifulSoup >>>from bs4 import BeautifulSoup 发现没有该模块 2.Linux输入 # pip install ...
- Http协议浅析
目录 Http协议浅析 http协议简介 http协议特性 http请求协议与响应协议 请求协议 响应协议 响应状态码 请求URI定位资源 HTTP方法 GET:获取资源 POST:传输实体主体 PU ...
- route命令使用
---恢复内容开始--- 利用route命令可以实现内外网同时访问 route 命令参数: route [-f] [-p] [Command [Destination] [mask Netmask] ...
- Django 通过APNS推送消息
最近手上一个项目需要通过APNS向app推送消息,由于后端采用drf框架,在github上找了好多模块,最终发现pzanitti大神的推送模块 django-push-notifications 比较 ...
- CORS (Cross Origin Resources Share) 跨域
CORS 跨域 1 什么是跨域问题 基于安全考虑,浏览器会限制使用脚本发起任何跨域请求. 所谓的跨域请求,就是与当前页面的 http/ip/port 不一样的请求. 但在实际运用中,跨域获取数据的需求 ...
- AOP-切面是如何织入到目标对象中的
切面是如何织入到目标对象中的???这大概是每个人在学习AOP的过程中都会产生的疑问吧. 当我们在调用目标方法时候,也就是通过代理对象调用目标方法的时候,比如:JdkDynamicAopProxy会通过 ...
- Android 4.4中AudioRecord用例 - 录制系统内置声音
通过API 19新加的MediaRecorder.AudioSource.REMOTE_SUBMIX參数能够让系统App录制系统内置的声音,也就是扬声器的声音.以下是一个巨简单的样例来演示样例怎样通过 ...
- shell基础--cat命令的使用
一.cat的常用用法 1.总结 2.实验 (1).非交互式编辑 [root@~_~ day5]# cat > cattest.sh <<STOP > hello > ST ...
- 使用 git push 出现error setting certificate verify locations问题记录
昨天重新装了个系统,使用时出现了error setting certificate verify locations. 出现错误仔细看错误提示,这可是解决问题的关键信息. 将错误的信息复制到搜索引擎中 ...
- Threadpool python3
from concurrent.futures import ThreadPoolExecutor,ALL_COMPLETED,wait,as_completedimport time def add ...