Expecting Different Types of Messages
Let’s discuss how threads can handle different types of messages.
We'll cover the following
receive()
receiveOnly()
can expect only one type of message. receive()
, on the other hand, can wait for more than one type of message. It dispatches messages to message handling delegates. When a message arrives, it is compared to the message type of each delegate. The delegate that matches the type of the particular message handles it.
For example, the following receive()
call specifies two message handlers that handle messages of types int
and string
, respectively:
Get hands-on with 1400+ tech skills courses.