我需要建一个线程,在定时器中利用该线程处理数据,我的流程是否正确?
1楼: 我做发如下:
先在public中声明
ReSendThread:Thread;
formcreate时:
ReSendThread:=Thread.Create(DealData); //建立线程
ReSendThread.Suspend; //先挂起
procedure TForm1.Timer2Timer(Sender: TObject);
begin
ReSendThread.Resume;//恢复线程
end;
procedure DealData() //处理数据
begin
end; 字串2 2楼: TThread不是组件,只能创建其派生类,Override Execute()才有意义,这样不行:ReSendThread:Thread;这句也不能这样写:ReSendThread:=Thread.Create(DealData);
还有用用Timer唤醒ReSendThread后,如果ReSendThread 是单线没有循环的,那么Timer唤醒ReSendThread后应该停止Time。。。。。
唉,实在搞不懂楼主要大家帮你确认什么? 字串1 3楼: TThread是抽象类,只能创建其派生类的实例
字串8
4楼: 老兄,你干吗这么写程序,很是莫名其妙字串4
5楼: 好像有点问题耶,把源代码贴出来看看! 字串5
6楼: 嘿嘿,好象还不是一丁点的问题,整个设计的思路就成问题。在Timer中Resume线程。 字串7 7楼: 我是这样做的,写一个线程,线程运行完处理过程后就自动释放,然后在定时器里创建该线程。 字串6
8楼: 介意楼主先看看些线程基础的东西,然后再动手做程序!我刚开始学DELPHI线程的时候,看了好多例程,才慢慢上手的...给我Email,发给你点资料...字串8
9楼: 那在Timer2中创建线程之前应该用一个IF语句判断线程实例是否存在,不存在才创建,如:
if ReSendThread=nil then //或if not Assigned(ReSendThread) then
begin
创建。。。
end
else
ReSendThread.Resume;//恢复线程
//线程中加上这句
FreeOnTerminate := True; 字串3