Solved

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

Posted on 2007-11-28
5
3,772 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
Comment Utility
0
 

Author Comment

by:BlahMatt
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
When you start your Windows 10 PC and got an "Operating system not found" error or just saw  "Auto repair for startup". After a while, you have entered a loop for Auto repair which does not fix anything and you will be in a  panic as all your work w…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

762 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

11 Experts available now in Live!

Get 1:1 Help Now