delphi中用api创建多线程的简单例子
procedure MyThread; stdcall;
begin
while True do
begin
end;
end;
procedure Func;
var
hThread:THandle;
ThreadId:Cardinal;
str:string;
begin
str := '123';
hThread := CreateThread(nil, 0, @MyThread, nil, 0, ThreadId);
if (WaitForSingleObject(hThread, 5000) = WAIT_TIMEOUT) then
begin
CloseHandle(hThread);
Form1.mmo1.Lines.Add('线程超时退出');
Exit;
end;
Form1.mmo1.Lines.Add('线程退出');
CloseHandle(hThread);
end;