Почему новый PingReply невозможен?C#

Место общения программистов C#
Ответить
Anonymous
 Почему новый PingReply невозможен?

Сообщение Anonymous »

При использовании метода SendPingAsync объекта System.Net.NetworkInformation.Ping выдается исключение PingException при попытке выполнить проверку связи с именем хоста, которое не разрешается (т. е. localhostnowhere).

Но при перехвате исключения невозможно создать новый PingReply?

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

  PingReply pingReply = null;
try
{
pingReply = await pingSender.SendPingAsync(host, timeout, buffer, options);
}
catch (PingException ex)
{
pingReply = new PingReply();
//other pingReply properties set here, like status  success, etc
}
catch (ArgumentNullException) { }
catch (Exception) { throw; }
Если посмотреть на определение PingReply, то у него нет конструктора по умолчанию. У него нет конструкторов.

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

#region Assembly System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
// C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.dll
#endregion

namespace System.Net.NetworkInformation
{
//
// Summary:
//     Provides information about the status and data resulting from a Overload:System.Net.NetworkInformation.Ping.Send
//     or Overload:System.Net.NetworkInformation.Ping.SendAsync operation.
public class PingReply
{
//
// Summary:
//     Gets the status of an attempt to send an Internet Control Message Protocol (ICMP)
//     echo request and receive the corresponding ICMP echo reply message.
//
// Returns:
//     An System.Net.NetworkInformation.IPStatus value indicating the result of the
//     request.
public IPStatus Status { get; }
//
// Summary:
//     Gets the address of the host that sends the Internet Control Message Protocol
//     (ICMP) echo reply.
//
// Returns:
//     An System.Net.IPAddress containing the destination for the ICMP echo message.
public IPAddress Address { get; }
//
// Summary:
//     Gets the number of milliseconds taken to send an Internet Control Message Protocol
//     (ICMP) echo request and receive the corresponding ICMP echo reply message.
//
// Returns:
//     An System.Int64 that specifies the round trip time, in milliseconds.
public long RoundtripTime { get; }
//
// Summary:
//     Gets the options used to transmit the reply to an Internet Control Message Protocol
//     (ICMP) echo request.
//
// Returns:
//     A System.Net.NetworkInformation.PingOptions object that contains the Time to
//     Live (TTL) and the fragmentation directive used for transmitting the reply if
//     System.Net.NetworkInformation.PingReply.Status is System.Net.NetworkInformation.IPStatus.Success;
//     otherwise, null.
public PingOptions Options { get; }
//
// Summary:
//     Gets the buffer of data received in an Internet Control Message Protocol (ICMP)
//     echo reply message.
//
// Returns:
//     A System.Byte array containing the data received in an ICMP echo reply message,
//     or an empty array, if no reply was received.
public byte[] Buffer { get; }
}
}
Как можно вернуть PingReply в случаях, когда пинг не увенчался успехом? Как Ping может вернуть новый PingReply?

Подробнее здесь: https://stackoverflow.com/questions/569 ... t-possible
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

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