title: C# SignalR Exception - Connection started reconnecting before invocation result was received
body: <p>I am developing 2 applications, the first being a C# console application and the other an Asp.net web application. I am using SignalR to connect the two. </p>
  
  <p>This is my C# console application (Client)</p>
  
  <pre><code>public class RoboHub
  {
      public static IHubProxy _hub;
  
      public RoboHub()
      {
          StartHubConnection();
          _hub.On("GetGoals", () =&gt; GetGoals());
          _hub.On("PrintMessageRobot", x =&gt; PrintMessageRobot(x));
  
          Thread thread = new Thread(MonitorHubStatus);
          thread.Start();
      }
  
      public void GetGoals()
      {
          //TODO: Does stuff
      }
  
      public void PrintMessageRobot(string msg)
      {
          Console.WriteLine(msg);
      }
  
      public void StartHubConnection()
      {
          Console.WriteLine("Robo Hub Starting");
          string url = @"http://localhost:46124/";
          var connection = new HubConnection(url);
          _hub = connection.CreateHubProxy("WebHub");
          connection.Start().Wait();
          Console.WriteLine("Robo Hub Running");
      }
  
      public void MonitorHubStatus()
      {
          while (true)
          {
              Thread.Sleep(1000);
              _hub.Invoke("Ping", "ping").Wait();
              Console.WriteLine("WebHub Pinged : " + DateTime.Now);
          }
      }
  }
  </code></pre>
  
  <p>When the console application runs, it creates an instance of the RoboHub class. Which in turn starts a connection to the SignalR hub and on a separate thread starts the method MonitorHubStatus which is something I implemented to check if the C# console application client is still actively connected to the hub. </p>
  
  <p>This is my Web hub (within the Asp.net Web application)</p>
  
  <pre><code>public class WebHub : Hub
  {
      /// &lt;summary&gt;
      /// This method should be called by the Web Clients. 
      /// This method should call the method on the robot clients.
      /// &lt;/summary&gt;
      public void GetGoalsHub()
      {
          lock (UserHandler.Connections)
          {
              if (UserHandler.Connections.Any(connection =&gt; connection.Contains("Robot")))
              {
                  Clients.All.GetGoals();
              }
          }
          //TODO add Error method to call on the client
      }
  
      /// &lt;summary&gt;
      /// Override Methods
      /// &lt;/summary&gt;
      /// &lt;returns&gt;&lt;/returns&gt;
      public override Task OnConnected()
      {
          lock (UserHandler.Connections)
          {
              //Find out who is connecting based on the User-Agent header
              var query = (from r in Context.Headers
                  where r.Key == "User-Agent"
                  select r).SingleOrDefault().ToString();
  
              if (query.Contains("SignalR.Client.NET45"))
              {
                  UserHandler.Connections.Add("Robot : " + Context.ConnectionId);
              }
              else
              {
                  UserHandler.Connections.Add("Web Application : " + Context.ConnectionId);
                  GetGoalsHub();
              }
          }
          Clients.All.UpdateConnections(UserHandler.Connections);
          return base.OnConnected();
      }
  
      public override Task OnDisconnected(bool stopCalled)
      {
          lock (UserHandler.Connections)
          {
              for (int i = 0; i &lt; UserHandler.Connections.Count; i++)
              {
                  if (UserHandler.Connections[i].Contains(Context.ConnectionId))
                  {
                      UserHandler.Connections.Remove(UserHandler.Connections[i]);
                  }
              }
          }
          Clients.All.UpdateConnections(UserHandler.Connections);
          return base.OnDisconnected(stopCalled);
      }
  
      public void Ping(string msg)
      {
          Clients.All.PrintMessageRobot("Pong : " + DateTime.Now);
      }
  }
  public static class UserHandler
  {
      public static List&lt;string&gt; Connections = new List&lt;string&gt;(); 
  }
  </code></pre>
  
  <p>Currently the 2 applications seem to work for a time, until after a while this error randomly appears: </p>
  
  <blockquote>
    <p>Connection started reconnecting before invocation result was received.</p>
  </blockquote>
  
  <p>Further more should the web hub call any other method on the C# console client such as the GetGoals method. The 'Ping Pong' method freezes and after time a similar exception is thrown. throughout this the web client continues to function perfectly and the web client can communicate back and forth with the hub server. </p>
  
  <p>Can anyone suggest what the issue could be?
  Edit: Further investigation leads me to believe it to be something to do with threading, however it is difficult to find the source of the issues. </p>