Re: GetIdleTime() - Help

Tech-Archive recommends: Speed Up your PC by fixing your registry



I tried using GetIdleTime and it provides very inconsistent results. The ratio is about 46% on the emulator (when idle), dropping down to 10-20% when in use. On a PPC Phone Edition it is constantly 0 - the function is apparently useless on it.

Consider opening and waiting for the following event:
"PowerManager/UserActivity_Inactive" (Using CreateEvent and WaitForMultipleObjects, or using EventEx class available in OpenNETCF SDF)


You cannot control the timeout period but the upside is that this is when the OS believes that the user is idle.

--
Alex Feinman
---
Visit http://www.opennetcf.org
"Rob S" <RobS@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message news:21C26A93-C50A-4FA2-A7F6-2F199E76BCE4@xxxxxxxxxxxxxxxx
Right ok....

Is there anyway one of you two can give me a small example of this working,
i'm kind of new to this PDA stuff and i'm running a bit short of time..


All i need is to give focus back to my application if the pda is idle for
more than 30 seconds.

Thanks, really appreciate it.

"Alex Feinman [MVP]" wrote:

For starters, GetTickCount does not give you a very precise interval
measurement. You would be better off using QueryPerformanceCounters. Because
of its coarsness, it is likely to return the same value before and after
DoEvents resulting in divide by zero condition. You should alway compare the
start and stop time and ignore measurement interval if they are the same.


I realize that the code you use is borrowed straight from the GetIdleTime
function documentation, but the sample code on MSDN has its share of
mistakes.

--
Alex Feinman
---
Visit http://www.opennetcf.org
"Rob S" <RobS@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:730C0F28-AAB9-41CA-8826-B88F697ACB3C@xxxxxxxxxxxxxxxx
> What's wrong with this code?
>
> [DllImport ("coredll.dll", SetLastError=false)]
> public static extern int GetIdleTime();
>
> [DllImport ("coredll.dll", SetLastError=false)]
> public static extern int GetTickCount();
>
>
> try
> {
> int dwStartTick = GetTickCount();
> int dwIdleSt = GetIdleTime();
>
> Application.DoEvents();
>
> int dwStopTick = GetTickCount();
> int dwIdleEd = GetIdleTime();
> int PercentIdle = ((100*(dwIdleEd - dwIdleSt)) / (dwStopTick -
> dwStartTick));
>
> MessageBox.Show(PercentIdle.ToString());
> }
> catch (Exception ex)
> {
> MessageBox.Show(ex.Message);
> }
>
> the main body of the code in a timer which fires every 20 seconds.
>
> The messagebox shows "0" the first time it runs then i get a divde by > zero
> error after that.
>
> any ideas?
>
> I need to give focus back to my application if the pda is idle for > longer
> than 30 seconds.
>
> Thanks guys.




.



Relevant Pages