Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Idle Detection in WPF

Tags:

c#

wpf

idle-timer

I'm new in using WPF so I have no Idea how to detect Idle time and show the main window after 5mins of Idle.

Can anyone help me? Thank you so much.

like image 637
Kuriyama Mirai Avatar asked Apr 25 '14 07:04

Kuriyama Mirai


People also ask

What is the idle detection API?

The Idle Detection API provides a means to detect the user's idle status, active, idle, and locked, specifically, and to be notified of changes to idle status without polling from a script. Native applications and browser extensions use idle detection base user experiences on when a user is interacting with a device.

How to detect if a process is running idle?

Hook into the System.Windows.Forms.Application.Idle event to help detect when the user is idle. Note, I said help.... If the user is idle, use System.Diagnostics.Process.GetCurrentProcess ().TotalProcessorTime to determine if the CPU is idle (at least for this process).

Is it possible to detect idle status without polling?

Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers. The Idle Detection API provides a means to detect the user's idle status, active, idle, and locked, specifically, and to be notified of changes to idle status without polling from a script.

What is the purpose of the Idle Class?

Please Sign up or sign in to vote. A utility class that alerts your code when the application is idle. If you've ever written a GUI (WinForms) application and wanted to periodically run a background process (such as poll a database), or need to log off the user or close a connection after a certain amount of inactivity, this class may be for you.


1 Answers

You can do;

var timer = new DispatcherTimer (
    TimeSpan.FromMinutes(5),
    DispatcherPriority.ApplicationIdle,// Or DispatcherPriority.SystemIdle
    (s, e) => { mainWindow.Activate(); }, // or something similar
    Application.Current.Dispatcher
);

picked up from here

like image 74
owenrumney Avatar answered Oct 01 '22 00:10

owenrumney