3

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?

4

1 回答 1

7

OnMessage 函数创建隐式监视器,它接收任务消息并调用您的匿名函数。OnTerminated 也是如此。

如果您希望使用 MonitorWith,您应该将消息处理和终止处理实现为监视器事件,而不是使用 OnMessage/OnTerminated 函数。

于 2013-08-29T11:03:50.917 回答