UserInterface thread option should use post (not send)

Topics: CAB & Smart Client Software Factory
Dec 12, 2007 at 9:08 AM
When CAB fires events onto a user interface thread it uses the send method of the user interface's synchronization context. I think it would be better if it used the post method, or better still, CAB should be extended to allow the subscriber to determine whether the event is posted or sent.

I had reason to write a program that had a user interface which controlled the starting and stopping of a worker thread (let's face it a common scenario). The worker thread published events to which the user interface subscribed. I discovered that whenever I tried to stop the worker thread the user interface and the worker thread got caught in the dreaded "deadly embrace". The user interface was waiting to "join" the worker thread at the same time as the worker thread was trying to fire an event on the user interface. Damned Deadlock!

The only workaround that I could think of was to fire the event from a background thread. This seems to defeat the purpose of CAB and seems a bit of a bodge.

If only the subscriber could have asked to have the event posted....