Index: /branches/thasling/DistributedGA/DistributedGA.Core/Implementation/WcfMessageService.cs
===================================================================
--- /branches/thasling/DistributedGA/DistributedGA.Core/Implementation/WcfMessageService.cs	(revision 14262)
+++ /branches/thasling/DistributedGA/DistributedGA.Core/Implementation/WcfMessageService.cs	(revision 14263)
@@ -1,4 +1,5 @@
 ﻿using System;
 using System.Net;
+using System.Net.NetworkInformation;
 using System.Net.Sockets;
 using System.ServiceModel;
@@ -24,23 +25,30 @@
       var serviceUrl = "DistributedGA.svc";
       new Thread(() => {
-        var baseUri = new Uri(string.Concat("net.tcp://", ip, ":", port, "/DistributedGA"));
-        var serviceUri = new Uri(baseUri, serviceUrl);
-        NetTcpBinding binding = new NetTcpBinding();
-        binding.MaxReceivedMessageSize = 20000000;
-        binding.MaxBufferSize = 20000000;
-        binding.MaxBufferPoolSize = 20000000;
-        binding.ReaderQuotas.MaxArrayLength = 20000000;
-        binding.ReaderQuotas.MaxDepth = 32;
-        binding.ReaderQuotas.MaxStringContentLength = 20000000;
+        try {
+          var baseUri = new Uri(string.Concat("net.tcp://", ip, ":", port, "/DistributedGA"));
+          var serviceUri = new Uri(baseUri, serviceUrl);
+          NetTcpBinding binding = new NetTcpBinding();
+          binding.MaxReceivedMessageSize = 20000000;
+          binding.MaxBufferSize = 20000000;
+          binding.MaxBufferPoolSize = 20000000;
+          binding.ReaderQuotas.MaxArrayLength = 20000000;
+          binding.ReaderQuotas.MaxDepth = 32;
+          binding.ReaderQuotas.MaxStringContentLength = 20000000;
 
-        using (var host = new ServiceHost(messageContract, serviceUri)) {
-          host.AddServiceEndpoint(typeof(IMessageContract), binding, serviceUri);
+          using (var host = new ServiceHost(messageContract, serviceUri)) {
+            host.AddServiceEndpoint(typeof(IMessageContract), binding, serviceUri);
 
-          host.Open();
+            host.Open();
 
-          _ResetEvent.WaitOne();
+            _ResetEvent.WaitOne();
+          }
+        }
+        catch (Exception ex) {
+          int k = 0;
+          int j = 0;
         }
       }).Start();
       return port;
+
     }
 
@@ -50,11 +58,44 @@
     }
 
+    private bool IsPortAvaiable(int port) {
+      //int port = 456; //<--- This is your value
+      bool isAvailable = true;
+
+      // Evaluate current system tcp connections. This is the same information provided
+      // by the netstat command line application, just in .Net strongly-typed object
+      // form.  We will look through the list, and if our port we would like to use
+      // in our TcpClient is occupied, we will set isAvailable to false.
+      IPGlobalProperties ipGlobalProperties = IPGlobalProperties.GetIPGlobalProperties();
+      TcpConnectionInformation[] tcpConnInfoArray = ipGlobalProperties.GetActiveTcpConnections();
+      foreach (TcpConnectionInformation tcpi in tcpConnInfoArray) {
+        if (tcpi.LocalEndPoint.Port == port) {
+          isAvailable = false;
+          break;
+        }
+      }
+      foreach (var item in ipGlobalProperties.GetActiveTcpListeners()) {
+        if (item.Port == port) {
+          isAvailable = false;
+          break;
+        }
+      }
+      return isAvailable;
+    }
+
     private int FreeTcpPort() {
-      TcpListener l = new TcpListener(IPAddress.Loopback, 0);
-      l.Start();
-      int port = ((IPEndPoint)l.LocalEndpoint).Port;
-      l.Stop();
-      return port;
+      for (int i = 11000; i <= 11100; i++) {
+        if (IsPortAvaiable(i))
+          return i;
+      }
+      return 0;
     }
+
+    //private int FreeTcpPort() {
+    //  TcpListener l = new TcpListener(IPAddress.Loopback, 0);
+    //  l.Start();
+    //  int port = ((IPEndPoint)l.LocalEndpoint).Port;
+    //  l.Stop();
+    //  return port;
+    //}
 
     private void OnMessageRecieved(object sender, MessageRecieveEventArgs e) {
Index: /branches/thasling/DistributedGA/DistributedGA.sln
===================================================================
--- /branches/thasling/DistributedGA/DistributedGA.sln	(revision 14262)
+++ /branches/thasling/DistributedGA/DistributedGA.sln	(revision 14263)
@@ -50,6 +50,3 @@
 		HideSolutionNode = FALSE
 	EndGlobalSection
-	GlobalSection(Performance) = preSolution
-		HasPerformanceSessions = true
-	EndGlobalSection
 EndGlobal
