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?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

    // process idle time here

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

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

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 ??
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

KaushikTannaAuthor Commented:
Yes . But I don't want to make my application as screen saver.
For 50 points?
KaushikTannaAuthor Commented:
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.
If you want to have an EXE calculating only in the systems's idle time, then decrease the priority of your process:



Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.