I have a Delphi 12 app that launches several threads that execute a task, that is, the same task repeated in N threads, there are no critical sections, no blocking or any other complications. Inside this task there is a TTimer that executes a method every so often. Everything works perfectly.
But I decided to modify the code and use TTaks to modernize the code a bit. Everything is perfect, except that the TTimer is given the time interval to execute, the method is passed, it is given enable to start the execution of the method but it does not do it even once.
It does not give errors or anything, the TTimer simply does not execute the method.
Is there some incompatibility problem between TTask and TTimer? Or is it that something special must be done for it to execute it?
var
TaskList: TList<ITask>;
T: ITask;
for i := 1 to spnCopias.Value do
begin
T := TTask.Run(
procedure
begin
THilosClientes.Create(i, False);
end
);
TaskList.Add(T);
end;
This is the code snippet where I launch the tasks. The start of the TTimer is :
...
Reloj := TTimer.Create(nil);
Reloj.Interval := 1000;
Reloj.Enabled := False;
...
Reloj.OnTimer := RelojOnTimer;
Reloj.Enabled := True;
The RelojOnTimer method is the one that executes several methods. The RelojOnTimer method never gets executed. I launched a single thread and executed it step by step, I never entered the RelojOnTimer method and no error was thrown.