gpt4 book ai didi

c# - Xamarin.iOS Ping导致System.InvalidOperationException

转载 作者:行者123 更新时间:2023-12-01 19:49:59 25 4
gpt4 key购买 nike

在我的代码中,我尝试执行以下操作:

Ping ping = new Ping();
var reply = ping.Send(ipAddress);

但是,这总是抛出System.InvalidOperationException:

“由于对象的当前状态,操作无效。”

我正在iOS9.1设备上运行它。

最佳答案

您不希望使用Mono Ping例程,因为它在iOS上不起作用。 Xamarin已将Apple的SimplePing示例代码包装到一个包/ nuget(Xamarin.SimplePing)中。

var pinger = new SimplePing("www.apple.com");

pinger.Started += (sender, e) => {
var endpoint = e.EndPoint;
pinger.SendPing(null);
};

pinger.ResponseRecieved += (sender, e) => {
var seq = e.SequenceNumber;
var packet = e.Packet;
};

pinger.Start();

回复: https://github.com/xamarin/XamarinComponents/tree/master/iOS/SimplePing

回复: https://developer.apple.com/library/content/samplecode/SimplePing

关于c# - Xamarin.iOS Ping导致System.InvalidOperationException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46464273/

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