windows系统里的事件都是用消息完成了,而且就是通过不停的监测完成的,我想应该只有一个办法,就是用一个timer,但建议判断的时候直接用Tdatetime型数据,不要转换为字符串。

解决方案 »

  1.   

    为什么不在系统中设置计划任务,让Windows定时执行你的程序,这样效率不是很高吗?象你这样,就得设计一个任务栏程序,或者是WinNT下的服务程序,编程工作量一点也不少呀!如果你非要做成这样的话,可以隔一分钟检测一次,你可以把这些工作做一个线程,不会对主程序有什么影响。
      

  2.   

    启动一个监测线程,
    execute 里面写:begin
      while not terminated do
      begin
        sleep(1000);
        KillVirus;  
      end;
    end;
      

  3.   

    procedure TForm1.FormCreate(Sender: TObject);
    begin
    Timer1.Enabled:= True;
    end;procedure TForm1.Timer1Timer(Sender: TObject);
    begin
    if TimeToStr(Time) = '09:00:00' then ...
    end;应该对效率不会有多大影响的。
      

  4.   

    unit Unit2;interfaceuses
      Classes, Syncobjs, mmsystem, Windows, SysUtils;type
      TPlan = class(TThread)
      private
        { Private declarations }
        FTime: TDateTime;
        FEvent: TEvent;
        FMMTimer: MMRESULT;
      protected
        procedure Execute; override;
      public
        constructor Create(ATime:TDateTime);
        destructor Destroy;override;
      end;implementation
    { TPlan }constructor TPlan.Create(ATime: TDateTime);
    begin
      FTime := ATime;
      FEvent := TEvent.Create(Nil,False,False,'');
      FreeOnTerminate := True;
      FMMTimer := timeSetEvent(1000,0,TFNTimeCallBack(FEvent.Handle),0,
                               TIME_PERIODIC or TIME_CALLBACK_EVENT_PULSE);
      inherited Create(False);
    end;destructor TPlan.Destroy;
    begin
      if FEvent <> nil then
        FEvent.Free;
      if FMMTimer <> 0 then
        timeKillEvent(FMMTimer);
      inherited;
    end;
    procedure TPlan.Execute;
    begin
      while not Terminated do
      begin
        FEvent.WaitFor(INFINITE);
        if Abs(Time-FTime) < 1/(24*3600) then//当前时间和指定时间相差不到一秒
        begin
          //do something you want to do;
        end;
      end;
    end;end.
    运行看一下,CPU占用率很低的.