Windows messages
The first option we have available is to use the Windows messaging system to send messages to the main thread. (This messaging system can also be used to send messages to a background thread, which is a more complicated topic that I will not pursue in this book.)
One limitation of this approach is obvious. We can only use it if we compile our program for Windows. If you are targeting other operating systems, you must use one of the other available solutions.
Another limitation is that a Windows message consists of a message ID and two integer parameters that represent message data. We cannot attach an object or a string as message data – at least not directly. We'll see how to circumvent this limitation later.
The ThreadedFooBar.WindowsMsg ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access