Processing Idle Time

I want processor's idle time.
Is any API is available for that? OR Give atleast 2 methods to get Processor's Idle time?
KaushikTannaAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
charlassConnect With a Mentor Commented:
If you want to have an EXE calculating only in the systems's idle time, then decrease the priority of your process:

SetPriority(
    GetCurrentProcess(),
    IDLE_PRIORITY_CLASS);

Bye!
0
 
noescomCommented:
I assume you want to process the idle time of Windows, when there are no events to process. You can do that as follows:

-- CODE EXAMPLE -----------------------

MSG msg; // holds the message

while(1) {
    if (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE)) {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }

    // process idle time here
}

-- END CODE EXAMPLE -------------------

0
 
KaushikTannaAuthor Commented:
Hi friend,
       What you had given is regarding windows idle time or it works to find out idle time in a process.But I want to find out for Whole window system. for e.g. I want to run a piece of code iff processor didn't get any input message for 30 mins.( just like how screen saver works).


0
[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

 
DarrinECommented:
the screensaver is really a system wide hook which assesses the last keyboard or mouse event - no event for the specified period and the screensaver kicks in

Is this what you are really looking for ??
0
 
KaushikTannaAuthor Commented:
Yes . But I don't want to make my application as screen saver.
0
 
NT_ProgrammerCommented:
For 50 points?
0
 
KaushikTannaAuthor Commented:
Hi friend,
Are the points very much or very less?I think u should not look at points while solving it.
0
 
NT_ProgrammerCommented:
If we should not look at points when solving it then the person asking a question should not have to specify points when asking a question and the person that answers the question shouldn't receive points for answering.

Believe it or not, this entire system is based on points.

What you are asking is a system related function.  And no, as far as I know, there is not one API that you can call to retrieve this information.  You have to do several things and decipher the results to get the processor idle time.  Thus my question "For 50 points?"

- FYI -
The code provided by noescom doesn't actually determin how much idle time there is in a process.  It only determines when a good time is to do processing when the process is idle.  But this code doesn't always run.  I've noticed that when the app is not the forground app the idle time code can not be depended upon to get called.
0
All Courses

From novice to tech pro — start learning today.