S
shameboy
Unregistered / Unconfirmed
GUEST, unregistred user!
我做两个线程控制消息发送/
B线程一直在工作,而A线程偶尔工作。当发现A线程有任务执行时,B线程必须先停止让A线程先执行,直到A任务完成B线程才继续下去。
-------------------------发现A有任务要执行
if TaskA_ADOQuery.RecordCount > 0 then
begin
TaskA_Timer.Enabled := False;
if (WaitForSingleObject(HThreadB_WriterData, 1) = WAIT_OBJECT_0)
or (WaitForSingleObject(HThreadB_WriterData, 1) = WAIT_TIMEOUT) then
//线程还在运行就把它挂起
begin
ccc := Server_Form.Tag;
SuspendThread(HThreadB_WriterData);
end;
-----------------------------执行完毕让给B继续
if WaitForSingleObject(HThreadB_WriterData, 1) <> WAIT_FAILED then
begin
Server_Form.Tag := ccc;
ResumeThread(HThreadB_WriterData);
end;
我这样做,经测试还是发现A执行时B也在执行。大家帮忙告诉一下线程暂停与继续的方法?
B线程一直在工作,而A线程偶尔工作。当发现A线程有任务执行时,B线程必须先停止让A线程先执行,直到A任务完成B线程才继续下去。
-------------------------发现A有任务要执行
if TaskA_ADOQuery.RecordCount > 0 then
begin
TaskA_Timer.Enabled := False;
if (WaitForSingleObject(HThreadB_WriterData, 1) = WAIT_OBJECT_0)
or (WaitForSingleObject(HThreadB_WriterData, 1) = WAIT_TIMEOUT) then
//线程还在运行就把它挂起
begin
ccc := Server_Form.Tag;
SuspendThread(HThreadB_WriterData);
end;
-----------------------------执行完毕让给B继续
if WaitForSingleObject(HThreadB_WriterData, 1) <> WAIT_FAILED then
begin
Server_Form.Tag := ccc;
ResumeThread(HThreadB_WriterData);
end;
我这样做,经测试还是发现A执行时B也在执行。大家帮忙告诉一下线程暂停与继续的方法?