title: Get number of listeners, clients connected to SignalR hub
body: <p>Is there a way to find out the number of listeners (clients connected to a hub?)</p>
  
  <p>I'm trying to run/start a task if at least one client is connected, otherwise do not start it:</p>
  
  <pre><code>[HubName("taskActionStatus")]
  public class TaskActionStatus : Hub, IDisconnect
  {
      static CancellationTokenSource tokenSource;
  
      public void GetTasksStatus(int? siteId)
      {
          tokenSource = new CancellationTokenSource();
          CancellationToken ct = tokenSource.Token;
  
          ITaskRepository taskRepository = UnityContainerSetup.Container.Resolve&lt;ITaskRepository&gt;();
  
          // init task for checking task statuses
          var tasksItem = new DownloadTaskItem();
          taskRepository.GetTasksStatusAsync(siteId, tasksItem, ct);
  
          // subscribe to event [ listener ]
          tasksItem.Changed += new EventHandler&lt;TaskEventArgs&gt;(UpdateTasksStatus);
      }
  
      public void UpdateTasksStatus(object sender, TaskEventArgs e)
      {
          Clients.updateMessages(e.Tasks);
      }
  
      // when browsing away from page
      public Task Disconnect()
      {
          try
          {
              tokenSource.Cancel();
          }
          catch (Exception)
          {
              //
          }
  
          return null;
      }
  }
  </code></pre>
  
  <p>thanks</p>