实时监测网络状态
定时器实时ping
private readonly string ip = "www.baidu.com";
Ping p = new Ping();
_ = new PingOptions
{
DontFragment = true
};
int timeout = 3000;//超时时间为3s
PingReply reply = p.Send(ip, timeout);
return reply.Status == IPStatus.Success;
添加配置文件
添加新项目--.config文件
内容:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v3.1" sku=".NETCore3.1" />
</startup>
<appSettings>
<add key=" " value=" ”/>
</appSettings>
</configuration>
读取:ConfigurationManager.AppSettings[”key“]