Jump to content
MarkShark

Notification message from an OmniWorkItem

Recommended Posts

I currently have a background worker that I use to serialize a queue of workitems.   The code to create the worker is:

  FWorker := Parallel.BackgroundWorker
    .NumTasks(1)
    .Execute(HandleWorkItem);

In this case the HandleWorkItem method is just a dummy method as I actually pass in the workitem code when I schedule the workitem.  E.g.:

 

  FWorker.Schedule(
    FWorker.CreateWorkItem(TOmniValue.FromRecord(MyWorkItemDataRec)),
    FWorker.Config.OnExecute(
      procedure(const workItem: IOmniWorkItem)
      var
        TaskResult: TTaskResult;
      begin
        // Do a bunch of work here in a background thread 
        // Now set the Result TOmniValue from a record.
        workItem.Result := TOmniValue.FromRecord(TaskResult);
      end)
    .OnRequestDone(DoneMethod)
  );
end;

 

This works extremely well, but I'd like to notify the calling thread of the progress.  I thought maybe that IOmniWorkItemConfig would have an OnMessage(eventHandler: TOmniTaskMessageEvent) that I could set during the Schedule call (much like OnRequestDone) but I haven't figured out how to do that.

 

Any help or suggestions appreciated.

 

Share this post


Link to post

Just wanted to mention that I realize I can add a notification handler to the entire FWorker with:

 

  FWorker := Parallel.BackgroundWorker
    .NumTasks(1)
    .TaskConfig(Parallel.TaskConfig.OnMessage(HandleTaskNotification))
    .Execute(HandleQueryWorkItem);

But I'm wondering if I can do a WorkItem specific handler with the Schedule() call.

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
×