views:

752

answers:

3

We want to activate a process if the user does not interact for 2 mins with our compact framework application running on our custom built devices.

I found an excellent C# sample code of Code Project(http://www.codeproject.com/KB/cs/ApplicationIdle.aspx) but it is not supported for compact framework as this code depends on Timers Class and Application.Idle events.

Can someone suggest me how to detect idle time?

A: 

Differences Between the .NET Compact Framework and the .NET Framework:

Timers The Start and Stop methods for a System.Timers.Timer object are not supported, but you can start and stop timing by setting the Enabled property of a System.Windows.Forms.Timer object to true or false.

You can also use System.Threading.Timer

Supported in: 3.5, 2.0, 1.0 .NET Compact Framework

You can use a Timer to detect idle activity like so: every time the user interacts with the application, reset a timer (that has an interval of say 5 minutes). If the Timer fires, then the application has been idle for 5 minutes.

Mitch Wheat
But there is no support for System.Windows.Forms.Application.Idle event in compact framework. That's where I'm struck now.
Gopinath
So he should put a timer reset in the Click for every Form andControl in the app? Seriously? How would that ever be maintainable?
ctacke
Hi Chris: that's not what I was suggesting. I done it before, by creating a base form containing the idle logic, and then inheriting from it.
Mitch Wheat
...which seems equivalent to the example you linked to.
Mitch Wheat
+1  A: 

I haven't used the .NET Compact Framework in nearly 4 years, but maybe this is something that you could P/Invoke? Or maybe OpenNetCF have something for this in their library? (that one saved me a couple of times back in the days.) I just did a quick search over there and they do have a class for Timers, you might want to check it out and see if it can help: http://www.opennetcf.com/library/sdf/

MetalMikester
+4  A: 

This blog entry is exactly what you need.

ctacke
Thanks a million
Gopinath
Not able to use this APIs on Windows XP box:http://stackoverflow.com/questions/1471794/unable-to-load-dll-coredll-dll-the-specified-module-could-not-be-found-on-wi
Gopinath