tags:

views:

555

answers:

6

To clarify, I mean time spent while the system is suspended/hibernated, not the calling thread (GetTickCount() returns the number of milliseconds since system boot).

+1  A: 

As far as I know, GetTickCount is unrelated to threads and counts the time since the system has started. But it is better to use GetTickCount64 to avoid the 49.7 day roleover.

By the way, to get what you want you need the GetThreadTimes function. It records the creation and exit time and the amount of time the thread has spend in user or kernel space. So you have a nice way to calculate the amount of time spend.

Ok, I missed the "system" part of the question. But that is simple. When in hibernation GetTickCount continues the counting. Because people have suffered from the 49.7 days bug when the computer was in hibernate most of the time. See link text here for more information.

Gamecat
I think the original question refers to whether the *system* is suspended or hibernated, not a particular thread.
Greg Hewgill
Point. Completely missed that one.
Gamecat
A: 

GetTickCount() gives you the time in milliseconds since the computer booted. it has nothing to do with the process calling it.

shoosh
What about if the computer is in hibernation not the process...
JoshBerke
I suppose the best way to find out is to just test it.
shoosh
A: 

Short answer : Yes.

Longer answer: Read the GetTickCount() docs: It's the elapsed time since system startup, and even MS wouldn't suggest that time stands still while your computer is hibernating...

Roddy
A: 

See rather GetTickCount() Win32 source code...

A: 

no, GetTickCount() does not include the time the system spend during hibernate. a simple test may i prove so.

in python import win32api win32api.GetTickCount()

-- do hiberante --

win32api.GetTickCount()

and you'll see the result..

accesomat
flat wrong and not helpful -- this bit of python has no way of allowing you to hibernate between the GetTickCount calls
Ben Bryant
A: 

Yes, GetTickCount does include suspend/hibernate time.

In the following python script I call the Sleep API to wait 40 seconds to give me a chance to put the computer into hibernate mode, and I print the time before and after, and the tick count difference after.

import win32api
import time
print time.strftime("%H:%M:%S", time.localtime())
before = win32api.GetTickCount()
print "sleep"
win32api.Sleep(40000)
print time.strftime("%H:%M:%S", time.localtime())
print str(win32api.GetTickCount()-before)

Output:

17:44:08
sleep
17:51:30
442297

If GetTickCount did not include the time during hibernate it would be much less than the time I hibernated for, but it matches the actual time elapsed (7 minutes 22 seconds equals 442 seconds, i.e. 442000 millisecond "ticks").

Ben Bryant