I am currently experimenting with OmniThreadLibrary. Enclosed is my code:
procedure TMainForm.LongWait;
begin
Task := Parallel.Future<string>(
function: string
begin
Sleep(10000);
Result := 'Done';
end,
Parallel.TaskConfig.OnTerminated(
procedure
begin
if Task.IsDone then
MessageDlg('Complete', mtInformation, [mbOK], 0)
else
MessageDlg('Exception', mtError, [mbCancel], 0)
end)
);
end;
I would call LongWait() and it works fine without blocking the UI. What I would like to do is:
- let the task run in the background while waiting for the value
- if an exception is raised, I want the main thread to catch it
- allow the main thread to determine if the task was completed or cancelled
Is it possible do a non-blocking function that would do all these?
Thank you in advance,
V.
EDIT: add the question