From 97a2b76856dc00fb46e9ff839556580b9920bde8 Mon Sep 17 00:00:00 2001 From: lidgren Date: Thu, 10 Mar 2011 18:45:18 +0000 Subject: [PATCH] Fixed shutdown iteration issue --- Lidgren.Network/NetPeer.Internal.cs | 21 ++++++++++++++------- UnitTests/Program.cs | 3 ++- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/Lidgren.Network/NetPeer.Internal.cs b/Lidgren.Network/NetPeer.Internal.cs index b60e83a..385d93d 100644 --- a/Lidgren.Network/NetPeer.Internal.cs +++ b/Lidgren.Network/NetPeer.Internal.cs @@ -156,16 +156,23 @@ namespace Lidgren.Network LogDebug("Shutting down..."); // disconnect and make one final heartbeat + var list = new List(m_handshakes.Count + m_connections.Count); lock (m_connections) { - foreach (NetConnection conn in m_connections) - conn.Shutdown(m_shutdownReason); - } + foreach (var conn in m_connections) + if (conn != null) + list.Add(conn); - lock (m_handshakes) - { - foreach (NetConnection conn in m_handshakes.Values) - conn.Shutdown(m_shutdownReason); + lock (m_handshakes) + { + foreach (var hs in m_handshakes.Values) + if (hs != null) + list.Add(hs); + + // shut down connections + foreach (NetConnection conn in list) + conn.Shutdown(m_shutdownReason); + } } // one final heartbeat, will send stuff and do disconnect diff --git a/UnitTests/Program.cs b/UnitTests/Program.cs index 411d381..fbfcdef 100644 --- a/UnitTests/Program.cs +++ b/UnitTests/Program.cs @@ -44,7 +44,8 @@ namespace UnitTests throw new Exception("Received error message!"); } } - + + Console.WriteLine("Done"); Console.ReadKey(); }