title: Send message every second to clients using signalR with C#
body: <p>I want to send some kind of timer to server to all connected clients.
  I was able to do this on button click. But what I really need is to send this timer every second automatically.</p>
  
  <p><strong>HTML</strong></p>
  
  <pre><code>&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head runat="server"&gt;
      &lt;title&gt;Signalr Chat Messenger&lt;/title&gt;
      &lt;script src="Scripts/jquery-1.6.4.min.js" type="text/javascript"&gt;&lt;/script&gt;
      &lt;script src="Scripts/jquery.signalR-1.0.0-rc1.js" type="text/javascript"&gt;&lt;/script&gt;
      &lt;script src="signalr/hubs" type="text/javascript"&gt;&lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;form id="form1" runat="server"&gt;
  
      &lt;script type="text/javascript"&gt;
          $(function () {
  
              var IWannaChat = $.connection.myChatHub;
  
              IWannaChat.client.addMessage = function (message) {
                  $('#listMessages').append('&lt;li&gt;' + message  + '&lt;/li&gt;');
              };
  
              IWannaChat.client.addTest = function (timer) {
                  $('#lblTimer').text(timer);
              };
  
              $("#SendMessage").click(function () {
                  IWannaChat.server.send($('#txtMessage').val());
              });
  
              $.connection.hub.start();
  
          });
      &lt;/script&gt;
  
      &lt;div&gt;
          &lt;input type="text" id="txtMessage" /&gt;
          &lt;input type="button" id="SendMessage" value="broadcast" /&gt;&lt;asp:Label ID="lblTimer" runat="server" Text="timer"&gt;&lt;/asp:Label&gt;
  &amp;nbsp;&lt;ul id="listMessages"&gt;
          &lt;/ul&gt;
      &lt;/div&gt;
      &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>and this is my <strong>HUB</strong></p>
  
  <pre><code>using System;
  using Microsoft.AspNet.SignalR.Hubs;
  using System.Threading;
  
  namespace SignalRChat
  {
      [HubName("myChatHub")]
      public class LetsChat : Hub
      {
          DateTime dateTime2 = DateTime.Now;
          string dateTime1 = "11.04.2016 15:49:00";   
  
  
  
  
          public void send(string message)
          {
              //Thread.Sleep(1000);
              var diffInSeconds = (Convert.ToDateTime(dateTime1) - dateTime2).TotalSeconds;
  
              Clients.All.addMessage(message);
              Clients.All.addTest(diffInSeconds.ToString());
              //Clients.All.addTest(dateTime1.ToString());
          }
  
  
      }
  }
  </code></pre>