0

I'm detecting inactivity of my WPF project. I've been using this code.

 readonly DispatcherTimer activityTimer;


    public MainWindow()
    {
        InitializeComponent();

        InputManager.Current.PreProcessInput += Activity;

        activityTimer = new DispatcherTimer
        {
            Interval = TimeSpan.FromSeconds(5),
            IsEnabled = true
        };
        activityTimer.Tick += Inactivity;

    }

    #region
    void Inactivity(object sender, EventArgs e)
    {


        FrameBody.Source = new Uri("Pages/Body.xaml", UriKind.Relative);


    }

    void Activity(object sender, PreProcessInputEventArgs e)
    {
        activityTimer.Stop();
        activityTimer.Start();


    }
    #endregion

It do work but there is only one problem. When the user doesn't do anything with the system, it do change the source of the frame FrameBody.Source = new Uri("Pages/Body.xaml", UriKind.Relative); But it also goes to the recent source of the frame.

In my system,I'm using 1 window with Frame. And the source of that frame changes depending on the user's interaction with the system. (ex. When the user click button then the source of that frame changes and when no click or sudden movement of the mouse for several seconds/minute, the source of the frame will change.)

Can anyone tell me what's wrong with my code? The code above is based from this WPF inactivity and activity

Community
  • 1
  • 1
Kuriyama Mirai
  • 867
  • 5
  • 17
  • 37
  • don't understand _But it also goes to the recent source of the frame_ part. But don't you want to add `activityTimer.Stop();` in your `Inactivity`? – Bolu Apr 30 '14 at 10:22
  • http://stackoverflow.com/questions/25516505/c-sharp-wpf-inactivity-and-activity-application-idle-user-inactivity-auto-l – sam Aug 26 '14 at 23:04

0 Answers0