先timer1.enable:=true;
后sleep(5000);
能在这个延时的5秒时间中响应timer事件吗?听说sleep过程中是不会响应任何东西
如果不响应,该怎么解决?

解决方案 »

  1.   

    能不能不用线程,而让在5s的延时过程中timer一直循环执行?
      

  2.   

    其实你可以不考虑用sleep,因为其实这个函数还是很占资源的,你就可以利用timer来使你所要进行的操作延长5秒钟,而且你也可以执行你另外想要进行的操作啊。
      

  3.   

    i:=0;
    while i<5000 do
    begin
      Sleep(Timer1.Interval);
      Application.ProcessMessages;
      Inc(i,Timer1.Interval);
    end;
      

  4.   

    用GetTickCount.
    var
     a,b: DWORD;
    begin
     a:=GetTickCount;
     while True do
     begin
      b:=GetTickCount;
      if ((b-a)>5000 then
      begin
       DoSomething;
      end
      else
      begin
       DoSomething;
      end;
     end;
    end;
      

  5.   

    用timer何必还可用sleep呢假如你的间隔时间是10秒
    也就是 timer1.Interval := 10000;
    开始时你多加五秒,也就是
    timer1.Interval := 15000;
    等第一次执行ontimer事件后
    再改为timer1.Interval := 10000;
    这样不是很好吗
      

  6.   

    type TimerThr:Tthreadprocedure timer1.ontimer...
    begin
      ...
    end;
    procedure execute;.......
    begin
      timer1.ontimer
      sleep(5000);
    end
      

  7.   

    修改
    type TimerThr:Tthread
    procedure timer1.ontimer...
    begin
      ...
    end;
    procedure execute;.......
    var
      i:boolean;
    begin
      I:=true
      while I:=true do
      begin
        timer1.ontimer;
        sleep(5000);
      end;
    end
      

  8.   

    用Timer就不用Sleep了
    Sleep中的程序没有响应的
    Timer就还有很好的响应的
      

  9.   

    hatedeadlock(雪男孩)的线程方法对么?
    在延时的时间内能响应ontimer事件吗?
      

  10.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, ExtCtrls, StdCtrls, Buttons;type
      TForm1 = class(TForm)
        Timer1: TTimer;
        BitBtn1: TBitBtn;
        procedure Timer1Timer(Sender: TObject);
        procedure BitBtn1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
    type
      Tmythr = class(TThread)
      private
        { Private declarations }
      protected
        procedure Execute; override;
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TMythr.Execute;
    var
      I:Boolean;
    begin
      I:=true;
      while I do
      begin
        Form1.Timer1Timer(self);
        sleep(5000);
      end;
    //
    end;procedure TForm1.Timer1Timer(Sender: TObject);
    begin
        Caption:=IntToStr(Random(100000)+1000);
    end;procedure TForm1.BitBtn1Click(Sender: TObject);
    var
      T:TMythr;
    begin
      T:=TMythr.Create(false);
      T.Priority:=tpidle;
    end;end.