?
Solved

.net Compact Framework: Timer is stopping when device goes into standby mode negating auto logout functionality

Posted on 2007-11-28
5
Medium Priority
?
3,809 Views
Last Modified: 2013-12-21
I'm developing an application in .net compact framework 2.0 (VB.net) for pocket pc's and one of the features that I implemented is an autologout timer.

If the user is inactive for a specified amount of time (specified by the user) the login screen will come up forcing them to log back in before proceeding. This works quite well in most situations, however, if the device goes into stand by the timer seems to stop. It will start up again when the user comes out of stand by mode, but it defeats the purpose. Basically if the device has a lower standby timeout time than the specified auto logout value, the user never gets logged out.

Thus far the only solutions I've been able to come up with are:

1. I can set the standby mode timeout from the code. So that it is 1 second greater than the autologout time (and set it back to whatever it was before if class closes)
2. Try to handle the "Into standby mode" and "Out of stand by mode" events and compare the system times between those 2 events and see if it has <-- I'm not sure if it's possible to handle these events and will require more investigation.
3. Figure out a way to have the timer run and bring up the login screen regardless of stand by mode.

I would prefer number 3 but I would accept 2 as well, but I'm not sure how to handle the events. After talking to my product people, 1 is not an option.
0
Comment
Question by:BlahMatt
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 48

Accepted Solution

by:
Mikal613 earned 750 total points
ID: 20367989
0
 

Author Comment

by:BlahMatt
ID: 20368360
I'll give that a shot

public enum PowerMode
{
ReevaluateStat = 0x0001,
PowerChange = 0x0002,
UnattendedMode = 0x0003,
SuspendKeyOrPwrButtonPressed = 0x0004,
SuspendKeyReleased = 0x0005,
AppButtonPressed = 0x0006
}

[DllImport("CoreDll.dll")]
public static extern void PowerPolicyNotify(PowerMode powermode, int flags);

On start of app:
PowerManagement.PowerPolicyNotify(PowerManagement.PowerMode.UnattendedMode, 1);

On end of app:
PowerManagement.PowerPolicyNotify(PowerManagement.PowerMode.UnattendedMode, 0);


Unfortunately one of our support people just came and took my device... I'll update later how it turns out.

Thanks Mikal
0
 
LVL 3

Assisted Solution

by:wizrr
wizrr earned 750 total points
ID: 20369901
Maybe you must implement your own timer. Try to use pinvoke to CreateTimer os something. Maybe you should use an separated thread with Sleep and event raising. Like this:
//that must be ISynchronizeInvoke, but .NET CF does not have it
Control controlSync = ...// your form
Thread thread = new Thread(new ParameterizedThreadStart(ThreadStart));
AutoResetEvent eventStart = new AutoResetEvent();
TimerCommand command = TimerCommand.Start;
thread.Start(controlSync);
int timerPeriod = 1000; // every second
TimerEvent doOnTimer = OnTimer;
//
...
public enum TimerCommand {
  Start,
  End
}
public delegate void TimerEvent();
...
//
private ThreadStart(Object syncObj) {
   Control controlSync = (Control)syncObj;
   while ( true ) {
      eventStart.WaitOne()
      if (command == Start) {
        while (command == Start) {
           if (eventStart.WaitOne(timerPeriod, false)) {
              // raise event
              // maybe timer does not work because it trying to sync invoke
              // with your app form
              // but application is sleepin (message loop suspended or something i dont know)
              controlSync.BeginInvoke(doOnTimer);
           } else {
             if (command == End) {
                return;
             }
           }
        }
      } else {
        return;
      }
   }
}

Open in new window

0
 

Author Comment

by:BlahMatt
ID: 20400100
Sorry it's taken me so long to respond. I tried both of those solutions and neither seems to work. I wrote a sample app that updates a text box on the timer fire event and implemented both solutions. The text box wouldn't update until I brought the ppc out of sleep mode.
0
 

Author Comment

by:BlahMatt
ID: 20451930
We ended up closing this as a known issue and telling users to set their auto logout value to less than the stand by value.

Thanks for everyones help.
0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A small collection of useful tips and tricks for Windows 10 users that I decided to write as a result of recent questions that were asked and answered at Experts Exchange. Two short video tutorials included. Enjoy..
In the absence of a fully-fledged GPO Management product like AGPM, the script in this article will provide you with a simple way to watch the domain (or a select OU) for GPOs changes and automatically take backups when policies are added, removed o…
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Suggested Courses
Course of the Month12 days, 8 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question