How to wait until OnRunFinished is executed

I do change taskInstance status onside a loop

while not dataset.eof do
taskInstance.Status := pStatus;

But I have some code on WorkflowStudio.OnRunFinished.
My loop change status faster than WorkflowStudio.OnRunFinished is executed;

How to force my loop to wait until the OnRunFinished event ends?

I tried add boolean variable on OnRunFinished and inside my loop I added empty while loop
 while not task_completed do; but the loop blocks my whole application and OnRunFinished event never execute!

You can't do that currently because the instances are signaled to run and they only execute on main thread (after your loop finished and execution goes idle).