Implementing the producer/consumer pattern
The blocks in the TPL Dataflow library provide a fantastic platform for implementing the producer/consumer pattern. If you are not familiar with this design pattern, it involves two operations and a queue of work. The producer is the first operation. It is responsible for filling the queue with data or units of work. The consumer is responsible for taking items from the queue and acting on them in some way. There can be one or more producers and one or more consumers in the system. You can change the number of producers or consumers, depending on which part of the process is the bottleneck.
Real-World Scenario Example
To relate the producer/consumer pattern to a real-world scenario, think about preparing gifts for a holiday gathering. You and a partner are working together to prepare the gifts. You are fetching and staging the gifts to be wrapped. You are the producer. Your partner is taking items from your queue and wrapping each gift...