-1

I do not know how to solve this problem:

I want in my WPF Application something like a screensaver which pops up (let's say after 20 seconds) if you do not interact with the program. I tried researching, but I did not find anything and I do not know how to start. Does anyone have any tips for me?

Scath
  • 3,777
  • 10
  • 29
  • 40
Adri1511
  • 21
  • 8
  • https://stackoverflow.com/questions/22619326/wpf-create-a-screen-saver-feature-when-application-is-inactive – kenny Apr 25 '18 at 14:04
  • Possible duplicate of [WPF: Create a screen-saver feature when application is inactive?](https://stackoverflow.com/questions/22619326/wpf-create-a-screen-saver-feature-when-application-is-inactive) – kenny Apr 25 '18 at 14:05

2 Answers2

0

You can for example start DispacherTimer and reset it if person move mouse or click something. In event check is time's up start new window/popup/dialog modal with screensaver, if person move mouse or click in screensaver close it and back to previous window.

Something about DispacherTimer you can find here: WPF Timer Like C# Timer or here https://msdn.microsoft.com/en-gb/library/system.windows.threading.dispatchertimer%28v=vs.90%29.aspx

Lit
  • 116
  • 5
0

You can do something like this then all you have to do is just set a timmer in the app.cs that resets.

    private DispatcherTimer _timer;
    protected override void OnStartup(StartupEventArgs e)
    {
        _timer = new DispatcherTimer();
        _timer.Tick += Timer_Tick;
        _timer.Interval = new TimeSpan(0,0,0,20,0);
        _timer.Start();

        EventManager.RegisterClassHandler(typeof(Window),Window.MouseMoveEvent, new RoutedEventHandler(Reset_Timer));
        EventManager.RegisterClassHandler(typeof(Window), Window.MouseDownEvent, new RoutedEventHandler(Reset_Timer));
        EventManager.RegisterClassHandler(typeof(Window), Window.KeyDownEvent, new RoutedEventHandler(Reset_Timer));
    }

    private void Timer_Tick(object sender, EventArgs e)
    {
        MessageBox.Show("Ticked");
    }

    private void Reset_Timer(object sender, EventArgs e)
    {
        _timer.Interval = new TimeSpan(0,0,0,20,0);
    }

This will reset the timer every time you move your mouse click your mouse or push any key in the window.

3xGuy
  • 2,235
  • 2
  • 29
  • 51