Application Time Out

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm looking for a convenient way to cause a .NET CF appliction to time out
after 5 minutes of inactivity. After a few days of digging around it appears
that I'm going to have to keep a global timer object and have each and every
form report mouse or keyboard activity to it. Does anyone out there have a
more centralized and elegant way of tracking application input activity?

Bill
 
Use the OpenNETCF ApplicationEx object and a message filter for mouse and
key messages. At each one, set an event. In a separate thread, wait on the
event with a timeout of the time you want in a loop. If the wait returns
with a time-out, rather than an event, indication, you've reached the idle
time-out and can do whatever you want.

Paul T.
 
It can be done using IMessageFilter from OpenNETCF library. You should
look for these messages:

const int WM_KEYUP = 0x0101;
const int WM_LBUTTONUP = 0x0202;

Also you will need a timer that will activate event every minute to see
if difference between Now value and the last action time is equal to 5
minute. Time event sends WM_TIMER (0x0113) message this could be handled
as well in your IMessageFilter. Here is a small code snippet:

DateTime _timeOfLastAction = DateTime.MaxValue;
public bool PreFilterMessage(ref Microsoft.WindowsCE.Forms.Message m)
{
switch(m.Msg)
{
case WM_KEYUP:
case WM_LBUTTONUP:
_timeOfLastAction = DateTime.Now;
if (inactive) {Activate(); return true;}
break;

case WM_TIMER:
if (!inactive && DateTime.Now.Subtract(timeOut) >
_timeOfLastAction) Inactivate();
break;
}
}


Best regards,
Sergey Bogdanov
http://www.sergeybogdanov.com
 
Awsome guys, thanks a lot!

Bill

Sergey Bogdanov said:
It can be done using IMessageFilter from OpenNETCF library. You should
look for these messages:

const int WM_KEYUP = 0x0101;
const int WM_LBUTTONUP = 0x0202;

Also you will need a timer that will activate event every minute to see
if difference between Now value and the last action time is equal to 5
minute. Time event sends WM_TIMER (0x0113) message this could be handled
as well in your IMessageFilter. Here is a small code snippet:

DateTime _timeOfLastAction = DateTime.MaxValue;
public bool PreFilterMessage(ref Microsoft.WindowsCE.Forms.Message m)
{
switch(m.Msg)
{
case WM_KEYUP:
case WM_LBUTTONUP:
_timeOfLastAction = DateTime.Now;
if (inactive) {Activate(); return true;}
break;

case WM_TIMER:
if (!inactive && DateTime.Now.Subtract(timeOut) >
_timeOfLastAction) Inactivate();
break;
}
}


Best regards,
Sergey Bogdanov
http://www.sergeybogdanov.com
 
Hi, Sergey,

Do you have a complete example of this topic in C#? I'd appreciate if you can
point it out for me.

Thanks,
Robert
 
Hi, Bill,

I'm having the same issue as you had before. It looks like you've got the
answer.
Could you please share with me the complete code in C#. I don't know how to
Activate() and InActivate() the application.

Thanks for the help.
Robert
 
Back
Top