关于如何每N秒做一些事情有很多提示,我发现没有明确说明这些方法是否由于延迟而缓慢地与系统时钟失去同步。
我在Windows上运行了一个多线程应用程序。我需要知道,在优先级较高的任务和线程允许的几毫秒内,一个特定的线程将根据系统时钟“精确地”在凌晨1点可靠地执行,然后在凌晨1点+ N秒,凌晨1点+ 2秒,等等。 ..并且在下午11点,晚上11点+ N点,晚上11点+ 2N点可靠地继续这样做,等等。是的 - 无论如何,情况都是这样(每小时都有N个第二期)。
我完全期望线程执行的实际时间是1am + d1,1am + N + d2,1am + 2N + d3,...其中每个d(i)是一些延迟增量。这一切都很好,只要delta值的分布保持合理一致且合理地低 - 通常最多几十毫秒,罕见的峰值高于此值。我不介意系统时钟是否与全球时间标准不同步。
我可以为此目的使用什么时序结构?是否存在维持同步本身的东西,或者我必须编写一些能够在处理器负载在白天上升和下降时保持自身同步以保持同步的代码?
答案 0 :(得分:4)
只要看看从现在到下次你应该醒来的时间,然后睡一段时间。因此,不是将重复计时器设置为每隔n 秒,而是在每次唤醒时设置一次性计时器,无论您需要在时间轴上从现在到下一个点之间经过多长时间。< / p>
更新:我已经编写了一个测试程序,看看重复计时器是否会漂移。 程序从下一分钟开始,然后每5秒唤醒一次: 这是运行一段时间后的结果(删除了一些无趣的位)。 摘要:实际上我不知道如何处理这些结果。 看起来就像Windows试图主动纠正计时器中的任何漂移一样,因此每次唤醒都发生在“适当的”时间。如果是这种情况,那么(为你想要的间隔设置一个计时器)绝对是实现你想要的最简单方法。#include <windows.h>
#include<stdio.h>
ULONGLONG convertTime(SYSTEMTIME st) {
FILETIME ft;
ULARGE_INTEGER tm;
SystemTimeToFileTime(&st, &ft);
tm.u.LowPart = ft.dwLowDateTime;
tm.u.HighPart = ft.dwHighDateTime;
return tm.QuadPart;
}
ULONGLONG getNextMinute() {
SYSTEMTIME now;
GetSystemTime(&now);
ULONGLONG ONE_MINUTE = 60 * 10000000;
ULONGLONG nowNumeric = convertTime(now);
ULONGLONG desiredTime = ((ULONGLONG)(nowNumeric / ONE_MINUTE)) * ONE_MINUTE + ONE_MINUTE;
return desiredTime;
}
int main(int argc, char* argv[]) {
ULONGLONG startTimeForTimer = getNextMinute();
HANDLE hTimer = NULL;
hTimer = CreateWaitableTimer(NULL, FALSE, NULL);
if (NULL == hTimer) {
printf("CreateWaitableTimer failed (%d)\n", GetLastError());
return 1;
}
printf("Waiting for the next minute to start...\n");
// Set a timer to wait for 5 seconds.
if (!SetWaitableTimer(hTimer, &startTimeForTimer, 5000, NULL, NULL, 0))
{
printf("SetWaitableTimer failed (%d)\n", GetLastError());
return 2;
}
// Wait for the timer.
SYSTEMTIME beforeTime;
SYSTEMTIME afterTime;
GetSystemTime(&beforeTime);
while (WaitForSingleObject(hTimer, INFINITE) == WAIT_OBJECT_0) {
GetSystemTime(&afterTime);
ULONGLONG elapsedTime = convertTime(afterTime) - convertTime(beforeTime);
printf("Timer was signaled: elapsed=%I64u, seconds=%02d.%02d\n", elapsedTime, afterTime.wSecond, afterTime.wMilliseconds);
GetSystemTime(&beforeTime);
}
return 0;
}
seconds=
位是当前分钟后的秒数(低至1000秒):Timer was signaled: elapsed=297650000, seconds=59.98
Timer was signaled: elapsed=50000000, seconds=04.986
Timer was signaled: elapsed=50000000, seconds=09.986
Timer was signaled: elapsed=50000000, seconds=14.986
Timer was signaled: elapsed=50000000, seconds=19.986
...
Timer was signaled: elapsed=50000000, seconds=09.986
Timer was signaled: elapsed=49990000, seconds=14.985
Timer was signaled: elapsed=50000000, seconds=19.985
...
Timer was signaled: elapsed=50000000, seconds=24.985
Timer was signaled: elapsed=49990000, seconds=29.984
...
Timer was signaled: elapsed=50000000, seconds=54.973
Timer was signaled: elapsed=50000000, seconds=59.973
Timer was signaled: elapsed=50000000, seconds=04.973
Timer was signaled: elapsed=49990000, seconds=09.972
Timer was signaled: elapsed=50000000, seconds=14.972
Timer was signaled: elapsed=50000000, seconds=19.972
Timer was signaled: elapsed=50000000, seconds=24.972
Timer was signaled: elapsed=50020000, seconds=29.974
Timer was signaled: elapsed=50020000, seconds=34.976
Timer was signaled: elapsed=50020000, seconds=39.978
Timer was signaled: elapsed=50020000, seconds=44.980
Timer was signaled: elapsed=50020000, seconds=49.982
Timer was signaled: elapsed=50020000, seconds=54.984
Timer was signaled: elapsed=50010000, seconds=59.985
Timer was signaled: elapsed=50020000, seconds=04.987
Timer was signaled: elapsed=50020000, seconds=09.989
Timer was signaled: elapsed=50020000, seconds=14.991
Timer was signaled: elapsed=50020000, seconds=19.993
Timer was signaled: elapsed=50020000, seconds=24.995
Timer was signaled: elapsed=50020000, seconds=29.997
Timer was signaled: elapsed=50020000, seconds=34.999
Timer was signaled: elapsed=50020000, seconds=40.01
Timer was signaled: elapsed=50020000, seconds=45.03
Timer was signaled: elapsed=50020000, seconds=50.05
Timer was signaled: elapsed=50020000, seconds=55.07
Timer was signaled: elapsed=50020000, seconds=00.09
Timer was signaled: elapsed=50010000, seconds=05.10
Timer was signaled: elapsed=50020000, seconds=10.12
Timer was signaled: elapsed=50020000, seconds=15.14
Timer was signaled: elapsed=50020000, seconds=20.16
Timer was signaled: elapsed=50020000, seconds=25.18
Timer was signaled: elapsed=50020000, seconds=30.20
Timer was signaled: elapsed=50020000, seconds=35.22
Timer was signaled: elapsed=50020000, seconds=40.24
Timer was signaled: elapsed=50020000, seconds=45.26
Timer was signaled: elapsed=50020000, seconds=50.28
Timer was signaled: elapsed=50020000, seconds=55.30
Timer was signaled: elapsed=50020000, seconds=00.32
Timer was signaled: elapsed=50010000, seconds=05.33
Timer was signaled: elapsed=50020000, seconds=10.35
Timer was signaled: elapsed=50020000, seconds=15.37
Timer was signaled: elapsed=50020000, seconds=20.39
Timer was signaled: elapsed=50020000, seconds=25.41
Timer was signaled: elapsed=50020000, seconds=30.43
Timer was signaled: elapsed=50020000, seconds=35.45
Timer was signaled: elapsed=50020000, seconds=40.47
Timer was signaled: elapsed=50020000, seconds=45.49
Timer was signaled: elapsed=50020000, seconds=50.51
Timer was signaled: elapsed=50020000, seconds=55.53
Timer was signaled: elapsed=50170000, seconds=00.70
Timer was signaled: elapsed=49870000, seconds=05.57
Timer was signaled: elapsed=50010000, seconds=10.58
Timer was signaled: elapsed=50020000, seconds=15.60
Timer was signaled: elapsed=50020000, seconds=20.62
Timer was signaled: elapsed=50020000, seconds=25.64
Timer was signaled: elapsed=50020000, seconds=30.66
Timer was signaled: elapsed=50020000, seconds=35.68
Timer was signaled: elapsed=50020000, seconds=40.70
Timer was signaled: elapsed=50020000, seconds=45.72
Timer was signaled: elapsed=50020000, seconds=50.74
Timer was signaled: elapsed=50020000, seconds=55.76
Timer was signaled: elapsed=50020000, seconds=00.78
Timer was signaled: elapsed=50020000, seconds=05.80
Timer was signaled: elapsed=50010000, seconds=10.81
Timer was signaled: elapsed=50020000, seconds=15.83
Timer was signaled: elapsed=50020000, seconds=20.85
Timer was signaled: elapsed=50020000, seconds=25.87
Timer was signaled: elapsed=50010000, seconds=30.88
Timer was signaled: elapsed=50010000, seconds=35.89
Timer was signaled: elapsed=50000000, seconds=40.89
Timer was signaled: elapsed=50010000, seconds=45.90
Timer was signaled: elapsed=50010000, seconds=50.91
Timer was signaled: elapsed=50000000, seconds=55.91
Timer was signaled: elapsed=50010000, seconds=00.92
Timer was signaled: elapsed=50010000, seconds=05.93
Timer was signaled: elapsed=50000000, seconds=10.93
Timer was signaled: elapsed=50010000, seconds=15.94
Timer was signaled: elapsed=50010000, seconds=20.95
Timer was signaled: elapsed=50000000, seconds=25.95
Timer was signaled: elapsed=50010000, seconds=30.96
Timer was signaled: elapsed=50010000, seconds=35.97
Timer was signaled: elapsed=50000000, seconds=40.97
Timer was signaled: elapsed=50010000, seconds=45.98
Timer was signaled: elapsed=50010000, seconds=50.99
Timer was signaled: elapsed=50000000, seconds=55.99
Timer was signaled: elapsed=50010000, seconds=00.100
Timer was signaled: elapsed=50010000, seconds=05.101
Timer was signaled: elapsed=50000000, seconds=10.101
Timer was signaled: elapsed=50010000, seconds=15.102
Timer was signaled: elapsed=50010000, seconds=20.103
Timer was signaled: elapsed=50010000, seconds=25.104
Timer was signaled: elapsed=50000000, seconds=30.104
Timer was signaled: elapsed=50010000, seconds=35.105
Timer was signaled: elapsed=50010000, seconds=40.106
Timer was signaled: elapsed=50000000, seconds=45.106
Timer was signaled: elapsed=50010000, seconds=50.107
Timer was signaled: elapsed=50010000, seconds=55.108
Timer was signaled: elapsed=50000000, seconds=00.108
Timer was signaled: elapsed=50010000, seconds=05.109
Timer was signaled: elapsed=50010000, seconds=10.110
Timer was signaled: elapsed=50000000, seconds=15.110
Timer was signaled: elapsed=50010000, seconds=20.111
Timer was signaled: elapsed=50010000, seconds=25.112
Timer was signaled: elapsed=50000000, seconds=30.112
Timer was signaled: elapsed=50010000, seconds=35.113
Timer was signaled: elapsed=50010000, seconds=40.114
Timer was signaled: elapsed=50000000, seconds=45.114
Timer was signaled: elapsed=50010000, seconds=50.115
Timer was signaled: elapsed=50010000, seconds=55.116
Timer was signaled: elapsed=50000000, seconds=00.116
Timer was signaled: elapsed=50010000, seconds=05.117
Timer was signaled: elapsed=50010000, seconds=10.118
Timer was signaled: elapsed=50000000, seconds=15.118
Timer was signaled: elapsed=50010000, seconds=20.119
Timer was signaled: elapsed=50010000, seconds=25.120
Timer was signaled: elapsed=50000000, seconds=30.120
Timer was signaled: elapsed=50010000, seconds=35.121
Timer was signaled: elapsed=50010000, seconds=40.122
Timer was signaled: elapsed=50000000, seconds=45.122
Timer was signaled: elapsed=50010000, seconds=50.123
Timer was signaled: elapsed=50010000, seconds=55.124
Timer was signaled: elapsed=50000000, seconds=00.124
Timer was signaled: elapsed=50010000, seconds=05.125
Timer was signaled: elapsed=50010000, seconds=10.126
Timer was signaled: elapsed=50000000, seconds=15.126
Timer was signaled: elapsed=50010000, seconds=20.127
Timer was signaled: elapsed=50010000, seconds=25.128
Timer was signaled: elapsed=50000000, seconds=30.128
Timer was signaled: elapsed=50000000, seconds=35.128
Timer was signaled: elapsed=50000000, seconds=40.128
Timer was signaled: elapsed=50010000, seconds=45.129
Timer was signaled: elapsed=50000000, seconds=50.129
Timer was signaled: elapsed=50000000, seconds=55.129
Timer was signaled: elapsed=50000000, seconds=00.129
Timer was signaled: elapsed=50000000, seconds=05.129
Timer was signaled: elapsed=50000000, seconds=10.129
Timer was signaled: elapsed=50010000, seconds=15.130
Timer was signaled: elapsed=50000000, seconds=20.130
Timer was signaled: elapsed=50000000, seconds=25.130
Timer was signaled: elapsed=50000000, seconds=30.130
Timer was signaled: elapsed=50000000, seconds=35.130
Timer was signaled: elapsed=50010000, seconds=40.131
Timer was signaled: elapsed=50000000, seconds=45.131
Timer was signaled: elapsed=50000000, seconds=50.131
Timer was signaled: elapsed=50000000, seconds=55.131
Timer was signaled: elapsed=50000000, seconds=00.131
Timer was signaled: elapsed=50010000, seconds=05.132
Timer was signaled: elapsed=50000000, seconds=10.132
Timer was signaled: elapsed=50000000, seconds=15.132
Timer was signaled: elapsed=50000000, seconds=20.132
Timer was signaled: elapsed=50000000, seconds=25.132
Timer was signaled: elapsed=50010000, seconds=30.133
Timer was signaled: elapsed=50000000, seconds=35.133
Timer was signaled: elapsed=50000000, seconds=40.133
Timer was signaled: elapsed=50000000, seconds=45.133
Timer was signaled: elapsed=50000000, seconds=50.133
Timer was signaled: elapsed=50010000, seconds=55.134
Timer was signaled: elapsed=50000000, seconds=00.134
Timer was signaled: elapsed=50000000, seconds=05.134
Timer was signaled: elapsed=50000000, seconds=10.134
Timer was signaled: elapsed=50000000, seconds=15.134
Timer was signaled: elapsed=50000000, seconds=20.134
Timer was signaled: elapsed=50010000, seconds=25.135
Timer was signaled: elapsed=50000000, seconds=30.135
Timer was signaled: elapsed=50000000, seconds=35.135
Timer was signaled: elapsed=50000000, seconds=40.135
Timer was signaled: elapsed=50000000, seconds=45.135
Timer was signaled: elapsed=50010000, seconds=50.136
Timer was signaled: elapsed=50000000, seconds=55.136
Timer was signaled: elapsed=50000000, seconds=00.136
Timer was signaled: elapsed=50000000, seconds=05.136
Timer was signaled: elapsed=50000000, seconds=10.136
Timer was signaled: elapsed=50010000, seconds=15.137
Timer was signaled: elapsed=50000000, seconds=20.137
Timer was signaled: elapsed=50000000, seconds=25.137
Timer was signaled: elapsed=50000000, seconds=30.137
Timer was signaled: elapsed=50000000, seconds=35.137
Timer was signaled: elapsed=50010000, seconds=40.138
Timer was signaled: elapsed=50000000, seconds=45.138
Timer was signaled: elapsed=50000000, seconds=50.138
Timer was signaled: elapsed=50000000, seconds=55.138
Timer was signaled: elapsed=50000000, seconds=00.138
Timer was signaled: elapsed=50010000, seconds=05.139
Timer was signaled: elapsed=50000000, seconds=10.139
Timer was signaled: elapsed=50000000, seconds=15.139
Timer was signaled: elapsed=50000000, seconds=20.139
Timer was signaled: elapsed=50000000, seconds=25.139
Timer was signaled: elapsed=50000000, seconds=30.139
Timer was signaled: elapsed=50000000, seconds=35.139
Timer was signaled: elapsed=50000000, seconds=40.139
Timer was signaled: elapsed=50000000, seconds=45.139
Timer was signaled: elapsed=50000000, seconds=50.139
Timer was signaled: elapsed=50000000, seconds=55.139
Timer was signaled: elapsed=50010000, seconds=00.140
Timer was signaled: elapsed=50000000, seconds=05.140
Timer was signaled: elapsed=50000000, seconds=10.140
Timer was signaled: elapsed=50000000, seconds=15.140
Timer was signaled: elapsed=50000000, seconds=20.140
Timer was signaled: elapsed=50000000, seconds=25.140
Timer was signaled: elapsed=50000000, seconds=30.140
Timer was signaled: elapsed=50000000, seconds=35.140
Timer was signaled: elapsed=50000000, seconds=40.140
Timer was signaled: elapsed=50000000, seconds=45.140
Timer was signaled: elapsed=50000000, seconds=50.140
Timer was signaled: elapsed=50000000, seconds=55.140
Timer was signaled: elapsed=50000000, seconds=00.140
Timer was signaled: elapsed=50000000, seconds=05.140
Timer was signaled: elapsed=50000000, seconds=10.140
Timer was signaled: elapsed=50000000, seconds=15.140
Timer was signaled: elapsed=50000000, seconds=20.140
Timer was signaled: elapsed=50000000, seconds=25.140
Timer was signaled: elapsed=50000000, seconds=30.140
Timer was signaled: elapsed=50000000, seconds=35.140
Timer was signaled: elapsed=50000000, seconds=40.140
Timer was signaled: elapsed=50000000, seconds=45.140
Timer was signaled: elapsed=50000000, seconds=50.140
Timer was signaled: elapsed=50000000, seconds=55.140
Timer was signaled: elapsed=50000000, seconds=00.140
Timer was signaled: elapsed=50000000, seconds=05.140
Timer was signaled: elapsed=50000000, seconds=10.140
Timer was signaled: elapsed=50000000, seconds=15.140
Timer was signaled: elapsed=50000000, seconds=20.140
Timer was signaled: elapsed=50000000, seconds=25.140
Timer was signaled: elapsed=50000000, seconds=30.140
Timer was signaled: elapsed=50010000, seconds=35.141
Timer was signaled: elapsed=50000000, seconds=40.141
Timer was signaled: elapsed=50000000, seconds=45.141
Timer was signaled: elapsed=50000000, seconds=50.141
Timer was signaled: elapsed=50000000, seconds=55.141
Timer was signaled: elapsed=50000000, seconds=00.141
Timer was signaled: elapsed=50000000, seconds=05.141
Timer was signaled: elapsed=50000000, seconds=10.141
Timer was signaled: elapsed=50000000, seconds=15.141
Timer was signaled: elapsed=50000000, seconds=20.141
Timer was signaled: elapsed=50000000, seconds=25.141
Timer was signaled: elapsed=50000000, seconds=30.141
Timer was signaled: elapsed=50000000, seconds=35.141
Timer was signaled: elapsed=50000000, seconds=40.141
Timer was signaled: elapsed=50000000, seconds=45.141
Timer was signaled: elapsed=50000000, seconds=50.141
Timer was signaled: elapsed=50000000, seconds=55.141
Timer was signaled: elapsed=50000000, seconds=00.141
Timer was signaled: elapsed=50000000, seconds=05.141
Timer was signaled: elapsed=50000000, seconds=10.141
Timer was signaled: elapsed=50000000, seconds=15.141
Timer was signaled: elapsed=50000000, seconds=20.141
Timer was signaled: elapsed=50000000, seconds=25.141
Timer was signaled: elapsed=50000000, seconds=30.141
Timer was signaled: elapsed=50000000, seconds=35.141
Timer was signaled: elapsed=50000000, seconds=40.141
Timer was signaled: elapsed=50000000, seconds=45.141
Timer was signaled: elapsed=50000000, seconds=50.141
Timer was signaled: elapsed=50000000, seconds=55.141
Timer was signaled: elapsed=50000000, seconds=00.141
Timer was signaled: elapsed=50000000, seconds=05.141
Timer was signaled: elapsed=50000000, seconds=10.141
Timer was signaled: elapsed=50000000, seconds=15.141
Timer was signaled: elapsed=50000000, seconds=20.141
Timer was signaled: elapsed=50000000, seconds=25.141
Timer was signaled: elapsed=50000000, seconds=30.141
Timer was signaled: elapsed=50000000, seconds=35.141
Timer was signaled: elapsed=50000000, seconds=40.141
Timer was signaled: elapsed=50000000, seconds=45.141
Timer was signaled: elapsed=50000000, seconds=50.141
Timer was signaled: elapsed=50000000, seconds=55.141
Timer was signaled: elapsed=50000000, seconds=00.141
Timer was signaled: elapsed=50000000, seconds=05.141
Timer was signaled: elapsed=50000000, seconds=10.141
Timer was signaled: elapsed=50000000, seconds=15.141
Timer was signaled: elapsed=49990000, seconds=20.140
Timer was signaled: elapsed=50000000, seconds=25.140
Timer was signaled: elapsed=50000000, seconds=30.140
Timer was signaled: elapsed=50000000, seconds=35.140
Timer was signaled: elapsed=50000000, seconds=40.140
Timer was signaled: elapsed=50000000, seconds=45.140
Timer was signaled: elapsed=50000000, seconds=50.140
Timer was signaled: elapsed=50000000, seconds=55.140
Timer was signaled: elapsed=50000000, seconds=00.140
Timer was signaled: elapsed=50000000, seconds=05.140
Timer was signaled: elapsed=50000000, seconds=10.140
Timer was signaled: elapsed=50000000, seconds=15.140
Timer was signaled: elapsed=50000000, seconds=20.140
Timer was signaled: elapsed=50000000, seconds=25.140
Timer was signaled: elapsed=50000000, seconds=30.140
Timer was signaled: elapsed=50000000, seconds=35.140
Timer was signaled: elapsed=50000000, seconds=40.140
Timer was signaled: elapsed=50000000, seconds=45.140
Timer was signaled: elapsed=50000000, seconds=50.140
Timer was signaled: elapsed=50000000, seconds=55.140
Timer was signaled: elapsed=50000000, seconds=00.140
Timer was signaled: elapsed=50000000, seconds=05.140
Timer was signaled: elapsed=50000000, seconds=10.140
Timer was signaled: elapsed=50000000, seconds=15.140
Timer was signaled: elapsed=50000000, seconds=20.140
Timer was signaled: elapsed=50000000, seconds=25.140
Timer was signaled: elapsed=50000000, seconds=30.140
Timer was signaled: elapsed=50000000, seconds=35.140
Timer was signaled: elapsed=50000000, seconds=40.140
Timer was signaled: elapsed=50000000, seconds=45.140
Timer was signaled: elapsed=50000000, seconds=50.140
Timer was signaled: elapsed=49990000, seconds=55.139
Timer was signaled: elapsed=50000000, seconds=00.139
Timer was signaled: elapsed=50000000, seconds=05.139
Timer was signaled: elapsed=50000000, seconds=10.139
Timer was signaled: elapsed=50000000, seconds=15.139
Timer was signaled: elapsed=50000000, seconds=20.139
Timer was signaled: elapsed=50000000, seconds=25.139
Timer was signaled: elapsed=50000000, seconds=30.139
Timer was signaled: elapsed=50000000, seconds=35.139
Timer was signaled: elapsed=50000000, seconds=40.139
Timer was signaled: elapsed=50000000, seconds=45.139
Timer was signaled: elapsed=50000000, seconds=50.139
Timer was signaled: elapsed=50000000, seconds=55.139
Timer was signaled: elapsed=50000000, seconds=00.139
Timer was signaled: elapsed=50000000, seconds=05.139
Timer was signaled: elapsed=50000000, seconds=10.139
Timer was signaled: elapsed=50000000, seconds=15.139
Timer was signaled: elapsed=50000000, seconds=20.139
Timer was signaled: elapsed=50000000, seconds=25.139
Timer was signaled: elapsed=49990000, seconds=30.138
Timer was signaled: elapsed=50000000, seconds=35.138
Timer was signaled: elapsed=50000000, seconds=40.138
Timer was signaled: elapsed=50000000, seconds=45.138
Timer was signaled: elapsed=50000000, seconds=50.138
Timer was signaled: elapsed=50000000, seconds=55.138
Timer was signaled: elapsed=50000000, seconds=00.138
Timer was signaled: elapsed=50000000, seconds=05.138
Timer was signaled: elapsed=50000000, seconds=10.138
Timer was signaled: elapsed=50000000, seconds=15.138
Timer was signaled: elapsed=50000000, seconds=20.138
Timer was signaled: elapsed=50000000, seconds=25.138
Timer was signaled: elapsed=50000000, seconds=30.138
Timer was signaled: elapsed=50000000, seconds=35.138
Timer was signaled: elapsed=50000000, seconds=40.138
Timer was signaled: elapsed=50000000, seconds=45.138
Timer was signaled: elapsed=49990000, seconds=50.137
Timer was signaled: elapsed=50000000, seconds=55.137
Timer was signaled: elapsed=50000000, seconds=00.137
Timer was signaled: elapsed=50000000, seconds=05.137
Timer was signaled: elapsed=50000000, seconds=10.137
Timer was signaled: elapsed=50000000, seconds=15.137
Timer was signaled: elapsed=50000000, seconds=20.137
Timer was signaled: elapsed=50000000, seconds=25.137
Timer was signaled: elapsed=50000000, seconds=30.137
Timer was signaled: elapsed=50000000, seconds=35.137
Timer was signaled: elapsed=50000000, seconds=40.137
Timer was signaled: elapsed=50000000, seconds=45.137
Timer was signaled: elapsed=50000000, seconds=50.137
Timer was signaled: elapsed=50000000, seconds=55.137
Timer was signaled: elapsed=50000000, seconds=00.137
Timer was signaled: elapsed=49990000, seconds=05.136
Timer was signaled: elapsed=50000000, seconds=10.136
Timer was signaled: elapsed=50000000, seconds=15.136
Timer was signaled: elapsed=50000000, seconds=20.136
Timer was signaled: elapsed=50000000, seconds=25.136
Timer was signaled: elapsed=50000000, seconds=30.136
Timer was signaled: elapsed=50000000, seconds=35.136
Timer was signaled: elapsed=50000000, seconds=40.136
Timer was signaled: elapsed=50000000, seconds=45.136
Timer was signaled: elapsed=50000000, seconds=50.136
Timer was signaled: elapsed=50000000, seconds=55.136
Timer was signaled: elapsed=50000000, seconds=00.136
Timer was signaled: elapsed=50000000, seconds=05.136
Timer was signaled: elapsed=50000000, seconds=10.136
Timer was signaled: elapsed=50000000, seconds=15.136
Timer was signaled: elapsed=50000000, seconds=20.136
Timer was signaled: elapsed=49990000, seconds=25.135
Timer was signaled: elapsed=50000000, seconds=30.135
Timer was signaled: elapsed=50000000, seconds=35.135
Timer was signaled: elapsed=50000000, seconds=40.135
Timer was signaled: elapsed=50000000, seconds=45.135
Timer was signaled: elapsed=50000000, seconds=50.135
Timer was signaled: elapsed=50000000, seconds=55.135
Timer was signaled: elapsed=50000000, seconds=00.135
Timer was signaled: elapsed=50000000, seconds=05.135
Timer was signaled: elapsed=50000000, seconds=10.135
Timer was signaled: elapsed=50000000, seconds=15.135
Timer was signaled: elapsed=50000000, seconds=20.135
Timer was signaled: elapsed=50000000, seconds=25.135
Timer was signaled: elapsed=50000000, seconds=30.135
Timer was signaled: elapsed=50000000, seconds=35.135
Timer was signaled: elapsed=50000000, seconds=40.135
Timer was signaled: elapsed=49990000, seconds=45.134
Timer was signaled: elapsed=50000000, seconds=50.134
Timer was signaled: elapsed=50000000, seconds=55.134
Timer was signaled: elapsed=50000000, seconds=00.134
Timer was signaled: elapsed=50000000, seconds=05.134
Timer was signaled: elapsed=50000000, seconds=10.134
Timer was signaled: elapsed=50000000, seconds=15.134
Timer was signaled: elapsed=50000000, seconds=20.134
Timer was signaled: elapsed=50000000, seconds=25.134
Timer was signaled: elapsed=50000000, seconds=30.134
Timer was signaled: elapsed=50000000, seconds=35.134
Timer was signaled: elapsed=50000000, seconds=40.134
Timer was signaled: elapsed=50000000, seconds=45.134
Timer was signaled: elapsed=50000000, seconds=50.134
Timer was signaled: elapsed=50000000, seconds=55.134
Timer was signaled: elapsed=49990000, seconds=00.133
Timer was signaled: elapsed=50000000, seconds=05.133
Timer was signaled: elapsed=50000000, seconds=10.133
Timer was signaled: elapsed=50000000, seconds=15.133
Timer was signaled: elapsed=50000000, seconds=20.133
Timer was signaled: elapsed=50000000, seconds=25.133
Timer was signaled: elapsed=50000000, seconds=30.133
Timer was signaled: elapsed=50000000, seconds=35.133
Timer was signaled: elapsed=50000000, seconds=40.133
Timer was signaled: elapsed=50000000, seconds=45.133
Timer was signaled: elapsed=50000000, seconds=50.133
Timer was signaled: elapsed=50000000, seconds=55.133
Timer was signaled: elapsed=50000000, seconds=00.133
Timer was signaled: elapsed=50000000, seconds=05.133
Timer was signaled: elapsed=50000000, seconds=10.133
Timer was signaled: elapsed=50000000, seconds=15.133
Timer was signaled: elapsed=49990000, seconds=20.132
Timer was signaled: elapsed=50000000, seconds=25.132
Timer was signaled: elapsed=50000000, seconds=30.132
Timer was signaled: elapsed=50000000, seconds=35.132
Timer was signaled: elapsed=50000000, seconds=40.132
Timer was signaled: elapsed=50000000, seconds=45.132
Timer was signaled: elapsed=50000000, seconds=50.132
Timer was signaled: elapsed=50000000, seconds=55.132
Timer was signaled: elapsed=50000000, seconds=00.132
Timer was signaled: elapsed=50000000, seconds=05.132
Timer was signaled: elapsed=50000000, seconds=10.132
Timer was signaled: elapsed=50000000, seconds=15.132
Timer was signaled: elapsed=50000000, seconds=20.132
Timer was signaled: elapsed=50000000, seconds=25.132
Timer was signaled: elapsed=50000000, seconds=30.132
Timer was signaled: elapsed=49990000, seconds=35.131
Timer was signaled: elapsed=50000000, seconds=40.131
Timer was signaled: elapsed=50000000, seconds=45.131
Timer was signaled: elapsed=50000000, seconds=50.131
Timer was signaled: elapsed=50000000, seconds=55.131
Timer was signaled: elapsed=50000000, seconds=00.131
答案 1 :(得分:2)
CreateWaitableTimer和SetWaitableTimer让你等待(WaitForSingleObject,或完成端口,或等待的任何东西)而不是睡觉。
另外,你可以给它一个精确的绝对时间或相对时间,无论你想要什么。如果你想要在凌晨1点之后精确地N秒,给它一个绝对时间为1 AM + N秒。
另外,如果计算机进入休眠状态,如果你指定它,它甚至可以工作。
答案 2 :(得分:1)
SetWaitableTimer
功能允许您指定特定的绝对时间和句点。
汉斯和亚当似乎关心的是使用一次性定时器时的处理时间漂移(即如果你因定时器而醒来,并为
您需要CreateWaitableTimer
,SetWaitableTimer
和其中一个等待函数,例如WaitForMultipleObjectsEx
。