Jump to content
hschmid67

Differenc between Task.Run and Task.Schedule

Recommended Posts

Hello,

If I understand everthing right (in the official book about OTL) then one needs no monitor if a task is scheduled (instead of run) - the monitor schould be implicit. I have a very simple example that runs not as expected (using OTL 3.07.6 Tokyo):

 

This code works (with and without the line ".MonitorWith(OmniEventMonitor1)"

 

for i := 1 to 3 do
begin
  CreateTask(
    procedure(const mTask: IOmniTask)
    begin
      CodeSite.Send('curmsg');
    end, 'hallo')
    .MonitorWith(OmniEventMonitor1)
    .Run;
end;

 

But this code does not. It works only with the line ".MonitorWith(OmniEventMonitor1)". Without nothing happens (no codesite messages).

 

for i := 1 to 3 do
begin
  CreateTask(
    procedure(const mTask: IOmniTask)
    begin
      CodeSite.Send('curmsg');
    end, 'hallo')
    .MonitorWith(OmniEventMonitor1)
    .Schedule;
end;

Did I miss something? After the second example I get a memory leak after closing my app (without the monitorwith).

 

Regards

Harald

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×