G.Thirunavukkarasu G.Thirunavukkarasu - 1 year ago 81
C# Question

How do i Add callBack Functionality to my hubClass in signalR for update the current work status to client with time delay?

I am new to signalR.I am developing a simple application in signalR. The Requirement is ,the signalR need to be update the current time to client repeatedly with some time delay.While i am starts running, the code i get server response for a time only.it's not repeated again and again. i need to callback the sameHubclass for update the current time to client again and again!

here is my Code:-

Javascript Client Code:-

<div class="container">
<input type="hidden" id="name" />
<script src="Scripts/jquery-1.6.4.min.js"></script>
<script src="Scripts/jquery.signalR-2.2.1.min.js"></script>
<script src="signalr/hubs"></script>
<script type="text/javascript">
$(function () {
var chat = $.connection.timeHub;
chat.client.broadcastMessage = function (name,current) {
var now = current;
+ now + '</strong></p>');

$("#name").val(prompt("Enter the UserName", ""));

$.connection.hub.start().done(function () {




public class timeHub : Hub
public void send(string name)


string current = DateTime.Now.ToString("HH:mm:ss:tt");

MyOwin Startup Class:-

[assembly: OwinStartup(typeof(Time.Startup))]

namespace Time
public class Startup
public void Configuration(IAppBuilder app)

How do i add callback functionality for my HubClass in Javascript Client Code in SignalR.

here is my current Output without callback function and timedelay:-

It update the current Client in  time only

but the signalR and .net client application or working fine.I need to time delay for hubclass and callback the samehub class periodically?

Here another output

Is it possible to callback the same hub class in server with some time delay?
For that i am added, time delay in hubclass. and i callback the hubclass in server .It won't work.Could anyone provide me an solution for this?

Answer Source

Ideally you would want to use a timer that calls the broadcastMessage method with the current time. There are some issues with your send hub method though. Also SignalR instantiates the hub class per each call and state is not maintained.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download