Mike Mike - 1 month ago 21
ASP.NET (C#) Question

How to make synchronous notification in asp.net

I'm using web forms in asp.net on my web app ,I need to make background process to check if there is new records inserted in my SQL Data Base every 10 minutes and give me a notification for it, How can i do that...Please help.

Answer

In global.asax Application_Start start a timer. When the timer fires use HostingEnvironment.QueueBackgroundWorkItem to call a function that does the DB-Query and notification via SignalR

void Application_Start(object sender, EventArgs e)
{
    var backgroundTimerTenMinutes = new System.Timers.Timer(600000);
    backgroundTimerTenMinutes.Elapsed += backgroundTimerTenMinutes_Elapsed;
}

void backgroundTimerTenMinutes_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
    HostingEnvironment.QueueBackgroundWorkItem(ct => DBQueryAndNotify(ct));
}
Comments