Solved

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

Posted on 2007-11-28
5
3,778 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Looking for good easy switch for lab at home. 13 86
C# Single Form 8 28
File Sharing with Apple and Windows 7 43
Recycle bin software for network mapped drives? 8 21
This is an article about Leadership and accepting and adapting to new challenges. It focuses mostly on upgrading to Windows 10.
Sometimes drives fill up and we don't know why.  If you don't understand the best way to use the tools available, you may end up being stumped as to why your drive says it's not full when you have no space left!  Here's how you can find out...
This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

895 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now