private void OnApplicationQuit() { if (_client != null) { _client.close(); _client.Abort(); } if (_server != null) { _server.close(); _server.Abort(); } }
/// <summary> /// Cierra la conexion a esta mquina remota.. los thread abort exception no detienen la ejecución /// </summary> public void close() { if (Interlocked.CompareExchange(ref closePoint, 1, 0) == 0) { try { senderStream.Close(0); } catch (ThreadAbortException e) { throw e; } catch (Exception) { } try { NetworkStream nStream = TcpClient.GetStream(); nStream.Close(0); } catch (ThreadAbortException e) { throw e; } catch (Exception) { } try { TcpClient.Client.Close(); } catch (ThreadAbortException e) { throw e; } catch (Exception) { } try { TcpClient.Close(); } catch (ThreadAbortException e) { throw e; } catch (Exception) { } try { ClientThread.Abort(); ClientThread.Join(); } catch (ThreadAbortException e) { throw e; } catch (Exception) { } closePoint = 0; } }