Solved

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

Posted on 2007-11-28
5
3,780 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
  • 3
5 Comments
 
LVL 48

Accepted Solution

by:
Mikal613 earned 250 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 250 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
When you try to extract and to view the contents of a Microsoft Update Standalone Package (MSU) for Windows Vista, you cannot extract the files from the MSU. Here we are going to explain how to extract those hotfix details without using any third pa…
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). …
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

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