Link to home
Start Free TrialLog in
Avatar of KaushikTanna
KaushikTanna

asked on

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?
Avatar of noescom
noescom

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 -------------------

Avatar of KaushikTanna

ASKER

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).


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 ??
Yes . But I don't want to make my application as screen saver.
For 50 points?
Hi friend,
Are the points very much or very less?I think u should not look at points while solving it.
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.
ASKER CERTIFIED SOLUTION
Avatar of charlass
charlass

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial