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
  • 63,281
  • 21
  • 137
  • 151
Kuriyama Mirai
  • 787
  • 5
  • 15
  • 36
  • 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

6

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,512
  • 2
  • 16
  • 36
  • 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
  • Thanks. I'll try this one. – Kuriyama Mirai Apr 25 '14 at 08:17