9

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.

dcastro
  • 66,540
  • 21
  • 145
  • 155
Kuriyama Mirai
  • 867
  • 5
  • 17
  • 37
  • You need to Maintain a timer for your WPF app .. Which get reset Whwnever any event occurs .. Thats how you can detect Idle time for your Application – spetzz Apr 25 '14 at 07:44

1 Answers1

5

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

owenrumney
  • 1,520
  • 3
  • 18
  • 37
  • How would the timer be reset when a user interacts with the application? – Clemens Apr 25 '14 at 07:54
  • Good point. maybe recreate the timer as a result of Window.Activated event firing. Then when user brings to focus it resets. Or create the time and just stop and start it on Activated. Maybe use `InputManager.Current.PreProcessInput` and reset in the handler for this – owenrumney Apr 25 '14 at 08:02
  • 3
    A more complete implementation on the same principle is here http://stackoverflow.com/a/4970019/2046117 – owenrumney Apr 25 '14 at 08:06