Click here to Skip to main content
15,899,314 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

How to get system idle duration in c#?
Posted
Comments
Tomas Takac 18-Dec-14 5:08am    

1 solution

I suggest to you to go for jquery instead.So, how do we calculate if the user is idle. Obeviously, until he/she has moved the mouse or pressed any key from the keyboard. So the solution is keep observing the mousemove & keypress event. Soon any of these event occurs, reset the idle time. Here is a sample code



var idleTime = 0;

$(document).ready(function () {
//Increment the idle time counter every minute.
var idleInterval = setInterval(timerIncrement, 60000); // 1 minute

//Zero the idle timer on mouse movement.
$(this).mousemove(function (e) {
idleTime = 0;
});
$(this).keypress(function (e) {
idleTime = 0;
});
});

function timerIncrement() {
idleTime = idleTime + 1;
if (idleTime > 19) { // 20 minutes
window.location.reload();
}
}



Hope it helps..:)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900