如果想实现不管啥时候启动程序,都是定时在某个时间启动线程,给你个办法:
function waitTimerProc(const p: pointer): integer;
begin
if (WaitForSingleObject(Cardinal(p), INFINITE) = WAIT_OBJECT_0) then
begin
{...你的线程执行代码}
end;
end;
procedure start;
var
st: SYSTEMTIME;
ft: FILETIME;
due: int64;
id: Cardinal;
hWaitTimer: Cardinal;
begin
// 可定时等待对象
hWaitTimer := CreateWaitableTimerA(nil, False, nil);
GetLocalTime(st);
st.wHour := 12;
// 12点0分
st.wMinute := 0;
SystemTimeToFileTime(st, ft);
LocalFileTimeToFileTime(ft, ft);
large_integer(due).LowPart := ft.dwLowDateTime;
large_integer(due).HighPart := ft.dwHighDateTime;
// 每24小时执行一次
SetWaitableTimer(hWaitTimer, due, 24 * 60 * 60 * 1000, nil, nil, False);
begin
Thread(nil, 0, @waitTimerProc, pointer(hWaitTimer), 0, id);
end;