private void AcceptConnection(IAsyncResult res) { try { socket = _listener.EndAccept(res); } catch (Exception) { if (!_controlledlistenerstop) { OnDirectConnectFailed("Client closed connection"); } return; } finally { try { _listener.Shutdown(SocketShutdown.Both); } catch (Exception) { } try { _listener.Close(); } catch (Exception) { } } // Stage one file sending starts OnDirectConnectReady(); }