I'm working on a project where I have to keep data that is up to date. I've been working on using a Timer to keep the data that my controller has synced with my DB every x seconds. My problem is that I can't get my View to Update/Refresh/Reload when the data is updated. I don't have to get the page to update without clicking anything on the page.
Index method
public ActionResult Index()
{
if (aTimer.Enabled == false)
{
initTimer();
}
var ordersLinks = db.OrdersLinks.Include(o => o.List).Include(s => s.Order_Stop_Link).Include(i => i.OrdersInfoes);
return View(ordersLinks.ToList());
}
Timer Event Timer is a System.Timers.Timer
public void TimerEvent(object sender, ElapsedEventArgs e)
{
var OldDB = db.OrdersLinks.FirstOrDefault().OrderNr;
foreach (var entity in db.ChangeTracker.Entries())
{
entity.Reload();
}
var NewDB = db.OrdersLinks.FirstOrDefault().OrderNr;
if (OldDB != NewDB)
{
Index(); //This calls into the Index Method but doesnt update the view
//RedirectToAction("Index");
}
}
SOLVED I used SignalR thanks to the comments, special thanks to @Stephen Muecke.