using OmniThreadLibrary I'd like to watch a task2 using another task1 to detect, if task2 is stopped or otherwise finished. The aim is to restart task2 if it stopped for any reason. Until now I use the following construct:
Task1 := CreateTask(
procedure(const mTask: IOmniTask)
begin
while not mTask.Terminated do
begin
Sleep(1000);
// create Task2 and run it, if it is not running
if Task2 = nil then
begin
Task2 := CreateTask(
procedure(const mTask: IOmniTask)
begin
while not mTask.Terminated do
begin
Sleep(1000);
end;
end)
.OnTerminated(procedure(const mTask: IOmniTaskControl)
begin
Task2 := nil;
end);
Task2.Run;
end;
end;
end)
.OnTerminated(
procedure(const mTask: IOmniTaskControl)
begin
Task1 := nil;
end);
Task1.Run;
If I try to terminate the inner task2 with this code
Task2.Terminate(10000);
I get the following error:
The same code work well with task1:
Task1.Terminate(10000);
Two questions:
I do not understand, what goes wrong with this code and what the "monitoring"-error means.
How can I get task1 to start task2 properly, and restart it, if task2 finished?
Thanks in advance