Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Asynchronous Agents and window messages

I'm currently playing with the Asynchronous Agents Library in Microsoft's Concurrency Runtime. I have not yet found an obvious way to signal that a task is finished by using window messages, or some other means of notifying the UI thread that the work is finished.

I know I can pass window handles and message values (WM_xxx) along to the tasks, and have the task use PostMessage() to signal the UI thread. This is somewhat ugly in my opinion, and a source of error. If an exception occurs, I have to have a catch handler that signals my UI thread. This is easily forgotten, and the exception condition might not be run very often, so it's hard to spot it.

The documentation talks about how to move data back to the UI thread. It does not make use of window messages, but polling techniques. I find it silly to set up timers to poll if a task has finished, when there are "interrupt" methods available!

It's kind of odd that this isn't built into the library, as it's not a cross platform library. It's designed to run on Windows, and Windows only, from what I understand.

Is the functionality available in the library, or do I have to hand roll this?

like image 858
Jörgen Sigvardsson Avatar asked Nov 13 '22 17:11

Jörgen Sigvardsson


1 Answers

You can create one monitor thread with sole function of monitoring an unbounded_buffer for a windows message and dispatching that message appropriately. Have your agents know about this buffer.

like image 106
Yuriy Gettya Avatar answered Dec 21 '22 00:12

Yuriy Gettya