我正在将 Delphi 应用程序从 Indy 9 更新到 Indy 10。
这很痛苦,因为显然发生了很多变化。
我被困在了一步。
这是旧代码(使用 Indy 9):
创建一个线程池,池中的每个线程都被初始化然后启动。各个线程创建一个 indy http 客户端(但在这里无关紧要)。
TUrlThread = class(TIdThread)
...
var
i: Integer;
begin
// create the Pool and init it
Pool := TIdThreadMgrPool.Create(nil);
Pool.PoolSize := Options.RunningThreads;
Pool.ThreadClass:= TUrlThread;
// init threads and start them
for i := 1 to Options.RunningThreads do
begin
with (Pool.GetThread as TUrlThread) do
begin
Index := i;
Controler := Self;
Priority := Options.Priority;
Start;
end;
end;
TIdThreadMgrPool类在 Indy 10 中消失了。
我一直在寻找替代品,而TIdSchedulerOfThreadPool看起来像是赢家,但我无法让它运行。
这是修改后的(Indy 10)代码:
TUrlThread = class(TIdThreadWithTask)
...
var
i: Integer;
begin
// create the Pool and init it
Pool := TIdSchedulerOfThreadPool.Create(nil);
Pool.PoolSize := Options.RunningThreads;
Pool.ThreadClass:= TUrlThread;
// init threads and start them
for i := 1 to Options.RunningThreads do
begin
with (Pool.NewThread as TUrlThread) do
begin
Index := i;
Controler := Self;
Priority := Options.Priority;
Start;
end;
end;
我在这里遇到访问冲突异常(这是 indy 代码):
procedure TIdTask.DoBeforeRun;
begin
FBeforeRunDone := True;
BeforeRun;
end;
FBeforeRunDone 为零。