idle state detection silverlight 4 application
Asked Answered
V

2

6

What's the best way to detect idle state for a silverlight application? I have read quite a few articles on the net by now and usually they are either for wpf/mobile apps etc.

I have created a DispatcherTimer which locks the screen after 5 minutes and it seems that I will have to go to every widget in every screen(my application has around 4-5 screens) and add a mousebuttondown or mouseenter eventhandler to reset this timer. This doesn't seem to be efficient but just adding the handler to the layroot is not helping either.

Any helpful suggestions?

Thanks

Version answered 23/6, 2011 at 9:25 Comment(0)
C
5

You don't need to modify every control. If you add the following code on startup:

Application.Current.RootVisual.MouseMove += new MouseEventHandler(RootVisual_MouseMove);
Application.Current.RootVisual.KeyDown += new KeyEventHandler(RootVisual_KeyDown);

With the following event handlers:

private void RootVisual_KeyDown(object sender, KeyEventArgs e)
{
    idle = false;
}

private void RootVisual_MouseMove(object sender, MouseEventArgs e)
{
    idle = false;
}

Where idle is the variable you use in your DispatcherTimer Tick event to check if things are happening or not.

As events bubble up the tree this should work for all your controls.

Continual answered 23/6, 2011 at 9:35 Comment(1)
@user64270: As long as you don't have ChildWindows open for longer than your idle timeout.Neumark
C
2

Handled events will not bubble up to root control. Instead you should use the AddHandler method with handledEventsToo = true.

Canvasback answered 13/3, 2012 at 22:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.