0

Applying timer in MVC Application which updates db on regular intervals. The below timer is not applying at application level because the script is being applied to only specific pages in application but not to the whole application. Is there any way I can apply timer at application level and update db at regular intervals

$(function () {

LastActivityTimer();
var active ;  
var LoggerTimer = '';



function LastActivityTimer() {

    $.getJSON('/Account/ActivityTimer/').done(function (value) {
        LoggerTimer = parseInt(value);

        active = setInterval(SaveLastActiveTime, LoggerTimer);


    });
}

function SaveLastActiveTime() {

                    $.ajax({
                        type: "POST",
                        url: '/Account/SaveLastActiveTime/',
                        cache: false,
                        //data: { userId: data.userId },
                        dataType: "json"
                    });
                }              
    }  

});
Ashu
  • 11
  • 5
  • What you want to do can be achieved by Session. Why are you making it so complicated? – Karan Nov 13 '18 at 05:17
  • check https://stackoverflow.com/a/12294671/9695286 for session start and end events in `global.asax`. You can set session timeout from `web.config`. – Karan Nov 13 '18 at 05:41
  • I have which logsout user for every 20min if user is inactive but here i want to update table for a periodic interval if user is active and update another column on table if user is inactive – Ashu Nov 13 '18 at 05:57
  • Okay, so it will automatically expire session after 20 minutes. If you add `void Session_End(object sender, EventArgs e) {` in `global.asax` then you can see that it will be execute after 20 minutes of inactivity of user. – Karan Nov 13 '18 at 05:59
  • @Karan I have InProc Session mode set to 20 min(web.config),If the user is inactive after 20 min user gets logged off and that's fine but i also want after 10min of user inactivity table value has to be updated.How to handle this? – Ashu Nov 16 '18 at 04:12

0 Answers0