Beispiel #1
0
 /// <summary>
 /// Stops the server and frees resources
 /// </summary>
 public void Stop()
 {
     lock (_lockCleanup)
     {
         //ensure all clients are disconnected and disposed
         while (_clients.Count > 0)
         {
             try
             {
                 var client = _clients[0];
                 client.Dispose();
                 _clients.Remove(client);
             }
             finally
             {
             }
         }
     }
     _cts?.Cancel();
     _cts?.Dispose();
     _cts = null;
     _thread?.Cancel();
     _thread = null;
     Stopped?.Invoke(this);
 }
Beispiel #2
0
 public void Cancel()
 {
     try //a hack
     {
         _thread?.Cancel();
     }
     catch { }
     //if (!_cts?.IsCancellationRequested ?? false)
     //    _cts?.Cancel();
 }
Beispiel #3
0
 /// <summary>
 /// Stops listening for and disconnects all current connections
 /// </summary>
 public void Stop()
 {
     while (_clients.Count > 0)
         _clients[0].Socket.Disconnect();
     _listenProc?.Cancel();
     _listenProc?.Join(1000);
     _listenProc = null;
     _server?.Stop();
     IsListening = false;
 }
Beispiel #4
0
 /// <summary>
 /// Stops listening for and disconnects all current connections
 /// </summary>
 public void Stop()
 {
     while (_clients.Count > 0)
     {
         _clients[0].DisconnectAsync().Wait();
     }
     _listenProc?.Cancel();
     _listenProc?.Join(1000);
     _listenProc = null;
     _server?.Stop();
     IsListening = false;
 }
Beispiel #5
0
 public void Stop()
 {
     lock (_lock)
     {
         if (_thread != null)
         {
             Mre.Set();
             _thread.Cancel();
             _thread.WaitForValue(t => t.IsRunning == false, 1000);
             _thread.Dispose();
             _thread = null;
         }
         Client?.Disconnect();
         Client = null;
     }
 }
Beispiel #6
0
 /// <summary>
 /// Stops sending data (this may leave messages unsent)
 /// </summary>
 public void Stop()
 {
     _thread?.Cancel();
     _thread = null;
 }
 /// <summary>Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.</summary>
 public void Dispose()
 {
     _thread?.Cancel(1000);
 }