This web site uses cookies. By using the site you accept the cookie policy.This message is for compliance with the UK ICO law.

<< Previous | 1 | 2 | 3 | 4 | Next >> |
Parallel LINQ and ForAllParallel LINQ and ForAll
The Parallel class defines loops that allow sequences of values to be enumerated in parallel. This can provide improved performance over sequential loops when the iterations are independent. When using PLINQ, the ForAll method provides such a loop.
Parallel For Loops for any Data TypeParallel For Loops for any Data Type
The standard parallel for loop is limited to working with integer values and only permits looping through an incrementing range, unlike its sequential equivalent. This article describes an alternative parallel for loop without these limitations.
Identifying Collection Indexes in Parallel ForEach LoopsIdentifying Collection Indexes in Parallel ForEach Loops
When using a sequential foreach loop it is simple to include a counter variable to determine the index of the item that is being operated upon. With parallel foreach loops the index must be identified in a different manner.
Cancelling Slow Parallel Loop IterationsCancelling Slow Parallel Loop Iterations
Parallel loops can be stopped early due to an exception being thrown or by calling the Break or Stop methods of the linked ParallelLoopState object. These actions do not cancel any scheduled iterations, which can be problematic for slow processes.
The ConcurrentBag&lt;T&gt; CollectionThe ConcurrentBag<T> Collection
With the introduction of the parallel task library, which simplifies parallel programming, the .NET framework was extended with several thread-safe collections. One of the simpler such collections is ConcurrentBag<T>.
Thread-Safe Stacks with ConcurrentStack&lt;T&gt;Thread-Safe Stacks with ConcurrentStack<T>
.NET 4.0 introduced several thread-safe collection types that can be used in parallel code without manual thread synchronisation. The ConcurrentStack<T> class is one such collection. It allows the creation of thread-safe, last-in, first-out stacks.
Thread-Safe Queues with ConcurrentQueue&lt;T&gt;Thread-Safe Queues with ConcurrentQueue<T>
The standard .NET queue classes are not thread-safe so require additional locking to avoid errors when used in multithreaded or parallel scenarios. This additional complexity is not required with the generic ConcurrentQueue<T> class.
Limiting Parallelism with Parallel.InvokeLimiting Parallelism with Parallel.Invoke
Parallel.Invoke can be used to launch several tasks that may execute in parallel. Depending upon the functionality of the tasks and their use of resources, it can be beneficial to limit the parallelism to a fixed number of concurrent tasks.
Limiting Loop ParallelismLimiting Loop Parallelism
For most parallel loops it's fine to allow the Task Parallel Library to determine the level of parallelism. The number of concurrent operations is set automatically to try to achieve better performance. In other cases it's important to limit parallelism.
Async and AwaitAsync and Await
Asynchronous operations are particularly suited to slow processes that would otherwise block the user interface thread and make applications unresponsive. In the past asynchronous code has been complicated to develop. .NET 4.5 simplifies this greatly.
<< Previous | 1 | 2 | 3 | 4 | Next >> |