var i:Integer; Addnum:array[0..9] of THandle; begin try for I := 0 to 9 do begin with TAddNumThread.Create(True) do begin Addnum[I] := Handle; FreeOnTerminate :=True; Start; end; end; WaitFormMultipleObjects(10,@Addnum,True,INFINITE);关闭了 except on E: Exception do Writeln(E.ClassName, ': ', E.Message); end; end.
只是执行了一些数值相加的动作.怎么把Readln;换成其它的?比如等待线程执行完的代码或其它的都可以使用WaitForMultipleObjects的话也不行.不知道怎么改,才能增加控制台的运行期~
你应该让你程序中的 Addnum[i].handle组成一个数组,然后用这个数字调用
WaitForMultipleObjects
而不是你程序中给出的线程对象指针数组作为等待数组
i:Integer;
Addnum:array[0..9] of THandle;
begin
try
for I := 0 to 9 do
begin
with TAddNumThread.Create(True) do
begin
Addnum[I] := Handle;
FreeOnTerminate :=True;
Start;
end;
end;
WaitFormMultipleObjects(10,@Addnum,True,INFINITE);关闭了
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
end.
for i:=0 to 99 do
begin
addnum[i].waitfor;
addnum[i].free;
end;
用你原来的代码,把Addnum[i].FreeOnTerminate :=True;去掉
然后把Readln;换成上边代码就可以了!
Sleep(10);