void HandleDisposed(UnrealAgentConnection c) { lock (ConnectionCreationLock) { if (c == connection) { connection = null; } } var evt = Disconnected; if (evt == null) { return; } try { evt(); } catch (Exception ex) { Log.Error(ex, "Unhandled exception"); } }
protected virtual void Dispose(bool disposing) { if (disposing && connection != null) { connection.Close(); connection = null; } }
/// <summary> /// Subclass should call this to close the connection. /// </summary> protected void CloseConnection() { lock (ConnectionCreationLock) { if (connection != null) { connection.Close(); } connection = null; } }
/// <summary> /// Subclass should call this when a connection is starting. /// </summary> protected UnrealAgentConnection OnConnecting(TcpClient client) { lock (ConnectionCreationLock) { if (connection != null) { connection.Dispose(); } connection = new UnrealAgentConnection(Log, client, HandleCommandBase, HandleDisposed); } return(connection); }