Migrating from Indy 9 to 10 with Delphi, initializing TIdSchedulerOfThreadPool

I am currently updating the Delphi application from Indy 9 to Indy 10.

This is rather painful, since, apparently, a lot has changed.

I'm stuck at one step.

Here is the old code (works with Indy 9):

A thread pool is created and each thread in the pool is initialized and then started. Separate threads are created by the indy client client (but it doesn’t matter here).

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;

The TIdThreadMgrPool class is missing since Indy 10.

I was looking for a replacement and TIdSchedulerOfThreadPool looks like a winner, but I can't get it to work.

Here is the modified code (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;

I get an access violation here (this is indy code):

procedure TIdTask.DoBeforeRun;
begin
  FBeforeRunDone := True;
  BeforeRun;
end;

FBeforeRunDone - zero.

+5
source share
1

, TIdSchedulerOfThreadPool Indy 10 TIdThreadMgrPool. , , , TIdScheduler TIdThreadMgr.

Indy 10, TIdThreadWithTask . , TIdThreadWithTask , TIdTask - (, TIdContext, Indy 10 TIdPeerThread), . , , . Start() , TIdTask TIdThreadWithTask.Task. TIdTCPServer , TIdScheduler.AcquireYarn() TIdYarn, TIdThreadWithTask, TIdContext TIdScheduler.StartYarn(), TIdYarn TIdThreadWithTask, Task, Start() .

. Indy 9 10 TIdThread.Start() . TIdTCPServer , ThreadMgr/Scheduler . , , . , .

:

TUrlThread = class(TIdThread)

...  

var
  i: Integer;
begin
  // create the Pool and init it
  Pool            := TIdThreadMgrPool.Create(nil);
  Pool.PoolSize   := Options.RunningThreads;
  Pool.ThreadClass:= TUrlThread;
  Pool.ThreadPriority := Options.Priority;

  // init threads and start them
  for i := 1 to Options.RunningThreads do
  begin
    with (Pool.GetThread as TUrlThread) do
    begin
      Index     := i;
      Controler := Self;
    end;
  end;

.

TUrlThread = class(TIdThreadWithTask)

...

var
  i: Integer;
begin
  // create the Pool and init it
  Pool            := TIdSchedulerOfThreadPool.Create(nil);
  Pool.PoolSize   := Options.RunningThreads;
  Pool.ThreadClass:= TUrlThread;
  Pool.ThreadPriority := Options.Priority;

  // init threads and start them
  for i := 1 to Options.RunningThreads do
  begin
    with (Pool.NewThread as TUrlThread) do
    begin
      Index     := i;
      Controler := Self;
    end;
  end;

, , , . Indy 9, 10, . PoolSize - , . PoolSize , , , . TUrlThread. Controler -, . Index , .

, . TIdThreadMgrPool.GetThread() TIdSchedulerOfThreadPool.NewThread() . Indy 9 10, , , Indy 10 TIdTCPServer. , , . , , , .

+7

All Articles