示例#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);
 }
示例#2
0
 public void Cancel()
 {
     try //a hack
     {
         _thread?.Cancel();
     }
     catch { }
     //if (!_cts?.IsCancellationRequested ?? false)
     //    _cts?.Cancel();
 }
示例#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;
 }
示例#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;
 }
示例#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;
     }
 }
示例#6
0
 /// <summary>
 /// Stops sending data (this may leave messages unsent)
 /// </summary>
 public void Stop()
 {
     _thread?.Cancel();
     _thread = null;
 }
示例#7
0
 /// <summary>Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.</summary>
 public void Dispose()
 {
     _thread?.Cancel(1000);
 }