protected override void OnUpdate() { base.OnUpdate(); List <ulong> toRemoveAgentIds = new List <ulong>(); var tmpAgents = new Dictionary <ulong, NetAgentBase>(m_netAgents); foreach (var kvPair in tmpAgents) { ulong id = kvPair.Key; NetAgentBase na = kvPair.Value; NetAgentState curr_state = na.GetState(); if (NetAgentState.Closed == curr_state || NetAgentState.Free == curr_state) { toRemoveAgentIds.Add(id); } na.UpdateIO(); } foreach (ulong id in toRemoveAgentIds) { RemoveNetAgent(id); } }