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