Question

I use OmniThreadLibrary 2.09 in my dll, main application and dll are using the same SimpleShareMem memory manager.

I created my own monitor with this code:

  FMonitor: TOmniEventMonitor;
  ...
  FMonitor := TOmniEventMonitor.Create(nil);

When I try to create a new task with this monitor, I'm getting an error "Task can be only monitored with a single monitor"

FTask := OtlTaskControl.CreateTask(TaskWorker)
  .OnMessage(
    procedure(const ATaskControl: IOmniTaskControl; const AMsg: TOmniMessage)
    begin
      ...
    end)
  .MonitorWith(FMonitor)  //  <----- Error
  .OnTerminated(
    procedure (const ATaskControl: IOmniTaskControl)
    begin
      ...
    end)
  .Run();

How can I monitor my task with my own monitor?

Was it helpful?

Solution

OnMessage function creates implicit monitor which receives the task message and calls your anonymous function. Same goes for OnTerminated.

If you wish to use MonitorWith, you should implement message processing and termination handling as a monitor events, not with OnMessage/OnTerminated functions.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top