gpt4 book ai didi

c# ping 类在 monodevelop 中抛出异常

转载 作者:太空宇宙 更新时间:2023-11-03 15:48:25 25 4
gpt4 key购买 nike

我的程序中有以下简单的 ping 方法。

    internal static bool Pinger(string host_to_ping = null)
{
bool network_available = NetworkInterface.GetIsNetworkAvailable();

int timeout_per_host_millis = 1000;

if (network_available)
{
Ping p = new Ping();

try
{
PingReply r = p.Send(host_to_ping, timeout_per_host_millis);

if (r.Status == IPStatus.Success)
return true;
}
catch { }
}
return false;
}

但是当 Ping p = new Ping(); 实例化它抛出...

An exception was thrown by the type initializer for System.Net.NetworkInformation.Ping

Monodelvelop 4.2.2Ubuntu 14.04 x64

最佳答案

几天前我遇到了同样的问题,最简单的修复/解决方法是以 root 身份运行 monodevelop。

例如打开终端并输入:

sudo monodevelop

现在以 root 身份打开 modevelop。打开您的项目并正常编译,您应该会看到它正确执行。

希望这对您有所帮助!

关于c# ping 类在 monodevelop 中抛出异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27040725/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com