A “dataflow block” is represented by a class implementing the IDataflowBlock interface. The state of a dataflow block is represented by the state of its IDataflowBlock.Completion Task, which itself has a Status property. When a dataflow block is in active state, meaning that it is currently doing processing or may do more processing in the...
ConcurrentDictionary is a popular concurrent data structure that was introduced in .NET 4. In the .NET 4.5 release, ConcurrentDictionary gets two performance improvements. One optimization is related to the way ConcurrentDictionary avoids torn reads and writes. To explain the background, all reference types and some value types are guaranteed...
Several times recently, folks have asked how to use tasks to implement the APM pattern, otherwise known as the Asynchronous Programming Model pattern, or the IAsyncResult pattern, or the Begin/End pattern. While moving forward we encourage folks to use a Task-based pattern for exposing asynchronous operation, the APM pattern has been the...
Of late, I’ve seen multiple folks asking about how to use tasks to asynchronously execute a sequence of operations. For example, given three synchronous functions: public string DoA(string input); public string DoB(string aResult); public string DoC(string bResult); you could invoke these functions with code like...
Recall that if exceptions thrown from Task bodies are left unobserved, they will be escalated. In .NET 4, this means that TPL will throw them on the finalizer after the Task objects are available for garbage collection. The UnobservedTaskException event on the TaskScheduler class was added as a last-resort method to observe such ...
In a previous post, we introduced the UnobservedTaskException event, saying that it would be useful for host-plugin scenarios where a host application should continue to execute in the presence of exceptions thrown by buggy plugins. A typical example is an Internet browser; should the entire application crash if some rich content plugin ...
(The full set of ParallelExtensionsExtras Tour posts is available here.) In a previous ParallelExtensionsExtras Tour blog post, we talked about implementing a custom partitioner for BlockingCollection<T>. Custom partitioning is an advanced but important feature supported by both Parallel.ForEach and PLINQ, as it allows the ...
(The full set of ParallelExtensionsExtras Tour posts is available here.)Producer/consumer scenarios could logically be split into two categories: those where the consumers are synchronous, blocking waiting for producers to generate data, and those where the consumers are asynchronous, such that they're alerted to data being available and only ...
(The full set of ParallelExtensionsExtras Tour posts is available here.)
Delegates in .NET may have one or more methods in their invocation list. When you invoke a delegate, such as through the Delegate.DynamicInvoke method, the net result is that all of the methods in the invocation list get invoked, one after the other.&...
(The full set of ParallelExtensionsExtras Tour posts is available here.)
Producer/consumer is a fundamental pattern employed in many parallel applications. With producer/consumer, one or more producer threads generate data that is consumed by one or more consumer threads. These consumers can themselves also be producers...