这是一个线程的最小可重现示例,该线程适用于 Windows 或 Linux,无需更改源代码并使用 Delphi 10.4.2:
program LinuxThreadDemo;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils,
System.Classes; // Contains TThread for both Windows and Linux
type
TMyThread = class(TThread)
procedure Execute; override;
end;
var
MyThread : TMyThread;
procedure TMyThread.Execute;
begin
WriteLn('Hello from thread');
end;
begin
try
MyThread := TMyThread.Create(TRUE);
try
MyThread.Start;
ReadLn;
finally
MyThread.Free;
end;
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
end.
Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号
执行时间: 0.0415198802948 seconds