Move the blocking code outside of the lock section to avoid race condition when shutting down.
Fixes [AMQNET-338]. (See https://issues.apache.org/jira/browse/AMQNET-338)

diff --git a/src/main/csharp/Transport/Tcp/TcpTransport.cs b/src/main/csharp/Transport/Tcp/TcpTransport.cs
index d2a00d5..5f1a21a 100644
--- a/src/main/csharp/Transport/Tcp/TcpTransport.cs
+++ b/src/main/csharp/Transport/Tcp/TcpTransport.cs
@@ -188,6 +188,8 @@
 
 		public void Close()
 		{
+			Thread theReadThread = null;
+
 			lock(myLock)
 			{
 				if(closed.CompareAndSet(false, true))
@@ -238,20 +240,27 @@
 					{
 					}
 
-					if(null != readThread)
+					theReadThread = this.readThread;
+					this.readThread = null;
+					this.started = false;
+				}
+			}
+
+			// Don't block on closing the read thread within the lock scope.
+			if(null != theReadThread)
+			{
+				try
+				{
+					if(Thread.CurrentThread != theReadThread && theReadThread.IsAlive)
 					{
-						if(Thread.CurrentThread != readThread && readThread.IsAlive)
+						if(!theReadThread.Join((int) MAX_THREAD_WAIT.TotalMilliseconds))
 						{
-							if(!readThread.Join((int) MAX_THREAD_WAIT.TotalMilliseconds))
-							{
-								readThread.Abort();
-							}
+							theReadThread.Abort();
 						}
-
-						readThread = null;
 					}
-
-					started = false;
+				}
+				catch
+				{
 				}
 			}
 		}