如果计算机是一直开着的,可以用计数的方式来实现任意时间长的定时器(最小时间
为系统的时间分辨率),假设你是以秒为计时单位,可如下编码:
struct T{
int year;
int month;
int day;
int hour;
int minute;
int second;
}timecount;
//in time-out process function:
timecount.second++;
if( timecount.second>=60 )
{
timecount.second = 0;
timecount.minute++;
if( timecount.minute>=60 )
{
timecount.minute = 0;
timecount.hour++;
...... // process other in same way
}
}
将Timer的 Interval设为1分钟(最大65535毫秒),在form的general中定义一个form 变量(dimlCounter as long =0)然后在Timer的 事件过程中,读出lCounter的值,判断是否与期望的时间相等(以分钟计,如时间为一小时:lCounter=60),如果相等就可执行相应程序代码,如需要可重置lCounter=0.