Error "Task can be only monitored with a single monitor" when setting my monitor to a task in dll

StackOverflow https://stackoverflow.com/questions/18508691

Вопрос

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?

Это было полезно?

Решение

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top