Introduction
As you have already learned, there are several approaches to creating asynchronous programs in .NET and C#. One of them is event-based asynchronous pattern, which has already been mentioned in the previous chapters. The initial goal of introducing events was to simplify the implementation of the Observer
design pattern. This pattern is common for implementing notifications between objects.
When we discussed the Task Parallel Library, we noted that the event's main shortcoming was their inability to be effectively composed with each other. The other drawback was that the Event-based Asynchronous Pattern was not supposed to be used to deal with the sequence of notifications. Imagine that we have IEnumerable<string>
that gives us string values. However, when we iterate it, we do not know how much time one iteration will take. It could be slow, and if we use the regular foreach
loop or other synchronous iteration constructs, we will block our thread until we have the next value...