'Pingcompletedeventargs.reply' nullC#

Место общения программистов C#
Anonymous
 'Pingcompletedeventargs.reply' null

Сообщение Anonymous »

Что заставляет ответ быть нулевым? Я строю игру через Unity3d. Но при строительстве и запуске на iOS (iPhone) ответ остается нулевым, хотя _respose.cancelled является false, а ошибка является нулевым? Телефон подключен к Интернету. < /P>

Код: Выделить всё

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 
, но никогда не объясняет, почему это может быть null ...

Подробнее здесь: https://stackoverflow.com/questions/614 ... ly-is-null

Вернуться в «C#»