3

I am creating an OmniWorker-Task to do some data processing.
So far, the Task is able to receive and send messages from/to other tasks.

Now I need to implement the main function for this task. This function will run continuously and do the data processing, while messages will modify it's behavior.

But where do I put this main function?
Is there anything like an "Execute"-method for an OmniWorker, that I need to implement?

Holgerwa
  • 3,430
  • 9
  • 42
  • 50

1 Answers1

6

Actually, TOmniWorker does not really support 'monolythic execution block + messaging' idiom. The whole idea behind TOmniWorker is that most of the code is executed in message handlers (and in the code called from them, of course) - as it is in the typical single-threaded Delphi application.

You can just send a special message ('Start!') and start your execution in the message handler but keep in mind that messages will not be processed while your message handler is executing. [To be more specific - you can send them but if you want to receive them you'll have to do it manually via Task.Comm.Receive.] This is not really unexpected as each TOmniWorker is a single-threaded environment and while it executes message handler it cannot do anything else.

gabr
  • 26,580
  • 9
  • 75
  • 141
  • 1
    Thanks for the explanation. Is there maybe a better approach for what I want to do? Basically, I need a thread with an execute method and message handling. If possible, using OTL. – Holgerwa Jan 20 '11 at 19:14
  • 4
    If you are doing a long processing and you want to process messages while this long processing is running, you'll have to receive messages yourself from the middle of this long processing. There's no better way. – gabr Jan 20 '11 at 20:02