title: SignalR hub hangs on IIS
body: <p>We use SignalR library in our ASP.NET web application. The code looks as following:</p>
  
  <p>Server:</p>
  
  <pre><code>[HubName("ticketsCounterHub")]
  public class MassivePrintHub : Hub
  {
      public void PostTicketsCount(long count)
      {
          Clients.All.Send(count);
      }
  }
  
  public class HubFactory
  {
      private HubFactory() {}
  
      public static readonly HubFactory Current = new HubFactory();
  
      public IHubProxy GetMassivePrintHubProxy()
      {
          var hubConnection = new HubConnection(ConfigUtils.GetRequiredSettingValue("adminPath"));
          var hubProxy = hubConnection.CreateHubProxy("ticketsCounterHub");
          hubConnection.Start().Wait();
          return hubProxy;
      }
  }
  </code></pre>
  
  <p>Client (JavaScript):</p>
  
  <pre><code>MassivePrintApp.controller("ListController", function ($scope, Dates) {
      var hubManager = (function () {
          var massivePrintHub = $.connection.ticketsCounterHub;
          $.connection.hub.start();
          return { massivePrintHub: massivePrintHub };
      } ());
  
      hubManager.massivePrintHub.client.Send = function (ticketsCount) {
          $scope.action.Quantity = ticketsCount;
          $scope.$digest();
      };
  });
  </code></pre>
  
  <p>The key part of code is in MVC controller:</p>
  
  <pre><code>public FileResult PrintAction(int actionId, int count, DateTime actionDate, bool isThermo=false)
  {
      var ticketsCount = _ticketService.GetTicketsInStatusCount(actionId, actionDate, TicketStatusEnum.ToPrint);
  
      HubFactory.Current.GetMassivePrintHubProxy().Invoke("PostTicketsCount", ticketsCount);
  
      var stream = new MemoryStream();
      xmlResponse.Save(stream);
      stream.Flush();
      stream.Position = 0;
      return File(stream,ContentTypeEnum.XML.ToString(),String.Format("массовая {0} мероприятия {1} {2}шт.xml", isThermo?"термопечать":"печать", action.Artist,count));
  }
  </code></pre>
  
  <p>As you can see, we have this line:</p>
  
  <pre><code>HubFactory.Current.GetMassivePrintHubProxy().Invoke("PostTicketsCount", ticketsCount);
  </code></pre>
  
  <p>And that causes the issue, that is whenever we call it one more instance of hub was added to "Requests" section on IIS.</p>
  
  <p>I understand we already started hub in JavaScript code, but I'm not sure how can I use the existing connection or how to get rid of HubFactory or delete created hub instance.</p>
  
  <p>And I don't understand why hub hangs on IIS.</p>