Class Pinger
Implements a threadsafe subset of the .NET Framework Ping class.
Namespace: Neon.Net
Assembly: Neon.Common.dll
Syntax
public class Pinger
Remarks
Unfortunately, the .NET Framework Ping class is not threadsafe (even the async methods). So, we need to ensure that only one ping request is performed on any given instance.
My original idea was to simply create and dispose Ping] instances on the fly for each request, but I changed my mind after thinking about the potential performance overhead as well as the potential for exhausting ephemeral socket ports.
Instead, I'm going to maintain a queue of Ping instances that that can be reused for subsequent queries.
Constructors
Pinger()
Constructor.
Declaration
public Pinger()
Methods
Clear()
Disposes any unused underlying Ping instances.
Declaration
public void Clear()
Dispose()
Releases all resources associated with the instance.
Declaration
public void Dispose()
Dispose(bool)
Releases all associated resources.
Declaration
protected virtual void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
bool | disposing | Pass |
~Pinger()
Finalizer.
Declaration
protected ~Pinger()
SendPingAsync(IPAddress, int)
Pings an IP address.
Declaration
public Task<PingReply> SendPingAsync(IPAddress address, int timeoutMilliseconds = 2000)
Parameters
Type | Name | Description |
---|---|---|
IPAddress | address | The target address. |
int | timeoutMilliseconds | Optional timeout in milliseconds (defaults to 2000). |
Returns
Type | Description |
---|---|
Task<PingReply> | A PingReply with the reply or an error indication. |
SendPingAsync(string, int)
Pings a IP address passed as a string
.
Declaration
public Task<PingReply> SendPingAsync(string address, int timeoutMilliseconds = 2000)
Parameters
Type | Name | Description |
---|---|---|
string | address | The target address. |
int | timeoutMilliseconds | Optional timeout in milliseconds (defaults to 2000). |
Returns
Type | Description |
---|---|
Task<PingReply> | A PingReply with the reply or an error indication. |