Re: GetIdleTime() - Help

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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

  • [PATCH v3] tools: create power/x86/turbostat
    ... turbostat is a tool to help verify proper operation of CPU idle power saving ... +unsigned int skip_c0; ...
    (Linux-Kernel)
  • Re: How many i am fingered?
    ... int main ... minutes 57 seconds idle ... Whenever a finger command is ran on perticular user, .plan file from ... can check the access time of the file and increment the counter (my be ...
    (comp.os.linux.development.system)
  • [cfq] sched_idle process stalled for 1 minute; strange ioprio too
    ... testing/unstable) and noticed that a massive 'apt-get upgrade' (300MB ... The machine was otherwise idle (top ... extern int sys_ioprio_set; ... ioprio = strtol; ...
    (Linux-Kernel)
  • Re: [PATCHv4 2/2] powerpc: implement arch_scale_smt_power for Power7
    ... int this_cpu, unsigned long *imbalance) ... I'm seeing check_asym_packing do the right thing with the simple SMT2 ... Do we need to give *imbalance a higher value? ... In my simple test case (SMT2, t0 idle, t1 active) if f_b_ghits our ...
    (Linux-Kernel)
  • Re: Get handle to System Idle Process? (Bill T?)
    ... As I mentioned in my "GetIdleTime not declared in SDK?" ... would increment a counter for the amount of idle time. ... get a handle to the OS idle loop thread and use the function ... Builder to support GetIdleTime. ...
    (microsoft.public.pocketpc.developer)