写一个函数如procedure forlistview; 然后在线程的 procedure Route1.Execute; begin while not Terminated do //这里可以保证不停循环监控类似timer功能 begin forlistview; // Synchronize( end; end;
while not Terminated do 有点启示了,再顶。消息队列是怎么回事?
...Execute; Var startT:int64;//起始时间 endT:int64; //当前时间 Freq:int64; // begin QueryPerformanceCounter(startT); QueryPerformanceFrequency(Freq); while not Terminated do begin QueryPerformanceCounter(endT); if (endT-startT)/Freq>=1 then //(endT-startT)/Freq得到的值的单位是Seconds //为防止因线程阻塞等问题引起超时 //而不能预期重置记时器所以使用'>=' begin //线程记时器代码 // QueryPerformanceCounter(startT);//开始新一轮记时 end; Sleep(10); //Sleep( milliseconds:Cardinal)的milliseconds最好大于0 end; end;
另外线程记时器执行代码最好写成一个函数,然后在Execute用Synchronize调用。
2个线程 做一监听标志 bTerminate 在其中监听的线程的Excute事件 while bTerminate do Synchronize(执行事件)
你可以在计时器的事件里新建线程。
在线程里写处理。
然后在线程的
procedure Route1.Execute;
begin
while not Terminated do //这里可以保证不停循环监控类似timer功能
begin
forlistview; // Synchronize(
end;
end;
Var
startT:int64;//起始时间
endT:int64; //当前时间
Freq:int64; //
begin
QueryPerformanceCounter(startT);
QueryPerformanceFrequency(Freq);
while not Terminated do
begin
QueryPerformanceCounter(endT);
if (endT-startT)/Freq>=1 then //(endT-startT)/Freq得到的值的单位是Seconds
//为防止因线程阻塞等问题引起超时
//而不能预期重置记时器所以使用'>='
begin
//线程记时器代码
//
QueryPerformanceCounter(startT);//开始新一轮记时
end;
Sleep(10); //Sleep( milliseconds:Cardinal)的milliseconds最好大于0
end;
end;
做一监听标志 bTerminate
在其中监听的线程的Excute事件
while bTerminate do
Synchronize(执行事件)
Application.CreateForm(TForm2, Form2);
Form2.ShowModal;
为什么编译时没错,运行老出错啊???