Parallel execution
In the previous section, the discussion was centered on the System.Threading.Tasks
namespace and the Task
class. Even though tasks are the cornerstone of the task-based asynchronous model and so-called Task Parallelism, the concurrent collections namespace makes up the Data Parallelism side of the async model and provides developers with tools to execute code most efficiently and in a thread-safe manner.
BlockingCollection<T>
is one of the concurrent collection implementations that encapsulates the core synchronization and coordination between threads and provides a thread-safe data storage to implement a provider-consumer model in Xamarin applications.
Using BlockingCollection<T>
, we can easily implement a new method that makes use of the parallel execution from the previous example. In this implementation, our view model will be the consumer and the Fibonacci source and the range calculation tasks will be the provider.
If we were to rewrite the range calculation...