I am trying to build a simple ASP.NET 5 app with SignalR which should push messages to clients at regular intervals (e.g. implement a dashboard with values pushed from the server to the browser.)
I researched some posts such as http://arulselvan.net/realtime-dashboard-asp-net-signalr-angularjs-d3js/ or http://henriquat.re/server-integration/signalr/integrateWithSignalRHubs.html. They recommend implementing a timer in a class implementing IRegisteredObject from the System.Web.Hosting namespace.
However, I don't seem to be able to locate the namespace where IRegisteredObject lives in ASP.NET 5. System.Web no longer exists in ASP.NET 5.
I haven't been able to find any info on it online.
What is the substitute for it in ASP.NET 5?
UPDATE
I am trying the following solution:
create a service encapsulating the timer
register it in
Startup.csas a singleton service, e.g.public class Ticker { Timer timer = new Timer(1000); public Ticker() { timer.Elapsed += Timer_Elapsed; timer.Start(); } private void Timer_Elapsed(object sender, ElapsedEventArgs e) { // do something } }
In Startup.cs
public void ConfigureServices(IServiceCollection services)
{
// ...
Ticker ticker = new Ticker();
ServiceDescriptor sd = new ServiceDescriptor(typeof(Ticker), ticker);
services.Add(sd);
// ...
}
How about this approach?