public async Task <IEnumerable <DiscoveryDevice> > Discover(int Timeout, IUdpClient client, CancellationToken cancellationToken = default(CancellationToken)) { var devices = new List <DiscoveryDevice> (); bool isRunning; await SendProbe(client); var responses = new List <UdpReceiveResult> (); try { isRunning = true; var cts = new CancellationTokenSource(TimeSpan.FromSeconds(Timeout)); while (isRunning) { if (cts.IsCancellationRequested || cancellationToken.IsCancellationRequested) { break; } var response = await client.ReceiveAsync().WithCancellation(cts.Token).WithCancellation(cancellationToken); responses.Add(response); } } catch (OperationCanceledException) { isRunning = false; } finally { client.Close(); } if (cancellationToken.IsCancellationRequested) { return(devices); } devices.AddRange(ProcessResponses(responses)); return(devices); }
private void Interrupt() { lock (commonClient) { if (!commonClient.IsClientNull()) { commonClient.Close(); } } }
protected virtual void Dispose(bool disposing) { if (disposing) { #if NET4 // IUdpClient does not implement IDisposable, but calling Close disables the // underlying socket and releases all managed and unmanaged resources associated // with the instance. client?.Close(); #else client?.Dispose(); #endif } }
/// <summary> /// Free resources held by the sink. /// </summary> /// <param name="disposing"> /// If true, called because the object is being disposed; if false, the object is being /// disposed from the finalizer. /// </param> protected override void Dispose(bool disposing) { base.Dispose(disposing); if (disposing && client != null) { #if NET4 // UdpClient does not implement IDisposable, but calling Close disables the // underlying socket and releases all managed and unmanaged resources associated // with the instance. client.Close(); #else client.Dispose(); #endif client = null; } }
public override void Close() { _client.Close(); }
public void Dispose() { _udpClient.Close(); }
/// <summary> /// Stops the server and threads for Login /// </summary> public void CloseServer() { _isRunning = false; _eventHandler.UdpPacketsRecived -= TryHandleInncommingPacket; _udpClient.Close(); }