Now, that we have covered the TPL's
Dataflow library and the set of objects it provides to assist in asynchronous message passing between concurrent tasks, let's take a look at the producer-consumer design pattern. In a typical producer-consumer design, we have one or more producers putting data into a queue or message data block. Then we have one or more consumers taking data from the queue and processing it. This allows for asynchronous processing of data. Using the
Dataflow library objects, we can create a consumer task that monitors a
BufferBlock and pulls items of the data from it when they arrive. If no items are available, the consumer method will block until items are available or the
BufferBlock has been ...