Код: Выделить всё
class MyPing{
public SNNI.Ping ping{ get; private set;} = null;
public Ip_Array ip{ get; private set;} = null;
public SNNI.PingCompletedEventArgs _response{ get; private set;} = null;
public bool _isDone{
get{ return _response != null; }
}
public MyPing( Ip_Array ip, int ms_timeout=1000 ){
this.ip = ip;
ping = new SNNI.Ping();
ping.PingCompleted += (object sender, SNNI.PingCompletedEventArgs r)=>{ _response = r; };
System.Net.IPAddress addr = new System.Net.IPAddress( ip.ip );
ping.SendAsync(addr, ms_timeout, null);
}
}
< /code>
.
//somewhere else:
p = new MyPing( new Ip_Array("0.0.0.0") );//
. < /p>
//later, checking every frame of the game:
if(p._isDone == false){ continue; }
if(p._response.Cancelled || p._response.Error != null){ continue; }
else{
Debug.Log(p._response.reply.Status);//throws exception because .reply is somewhow 'null'
}
< /code>
Интересно, что есть пример использования pingcompletedeventargs, в частности, метод DisplayReply () < /code>. Там они проверяют, ответить ли ответ == null Подробнее здесь: https://stackoverflow.com/questions/614 ... ly-is-null