Free Sample
+ Collection

.NET 4.5 Parallel Extensions Cookbook

Bryan Freeman

If you’re an experienced C# developer, this book will give you the know-how to exploit the power of multicore processors. Its 80 recipes provide an in-depth guide to using .NET 4.5 to enhance application performance and scalability.
RRP $29.99
RRP $49.99
Print + eBook

Want this title & more?

$12.99 p/month

Subscribe to PacktLib

Enjoy full and instant access to over 2000 books and videos – you’ll find everything you need to stay ahead of the curve and make sure you can always get the job done.

Book Details

ISBN 139781849690225
Paperback336 pages

About This Book

  • Create multithreaded applications using .NET Framework 4.5
  • Get introduced to .NET 4.5 parallel extensions and familiarized with .NET parallel loops
  • Use new data structures introduced by .NET Framework 4.5 to simplify complex synchronisation problems
  • Practical recipes on everything you will need to create task-based parallel programs

Who This Book Is For

This book is intended to help experienced C# developers write applications that leverage the power of modern multicore processors. It provides the necessary knowledge for an experienced C# developer to work with .NET parallelism APIs. Previous experience of writing multithreaded applications is not necessary.

Table of Contents

Chapter 1: Getting Started with Task Parallel Library
Creating a task
Waiting for tasks to finish
Returning results from a task
Passing data to a task
Creating a child task
Lazy task execution
Handling task exceptions using try/catch block
Handling task exceptions with AggregateException.Handle
Cancelling a task
Cancelling one of many tasks
Chapter 2: Implementing Continuations
Continuing a task
Passing task results to a continuation
Continue "WhenAny" and "WhenAll"
Specifying when a continuation will run
Using a continuation for exception handling
Cancelling a continuation
Using a continuation to chain multiple tasks
Using a continuation to update a UI
Chapter 3: Learning Concurrency with Parallel Loops
Creating a basic parallel for loop
Creating a basic parallel foreach loop
Breaking a parallel loop
Stopping a parallel loop
Cancelling a parallel loop
Handling exceptions in a parallel loop
Controlling the degree of parallelism in a loop
Partitioning data in a parallel loop
Using Thread Local Storage
Chapter 4: Parallel LINQ
Creating a basic parallel query
Preserving order in parallel LINQ
Forcing parallel execution
Limiting parallelism in a query
Processing query results
Specifying merge options
Range projection with parallel LINQ
Handling exceptions in parallel LINQ
Cancelling a parallel LINQ query
Performing reduction operations
Creating a custom partitioner
Chapter 5: Concurrent Collections
Adding and removing items to BlockingCollection
Iterating a BlockingCollection with GetConsumingEnumerable
Performing LIFO operations with ConcurrentStack
Thread safe data lookups with ConcurrentDictionary
Cancelling an operation in a concurrent collection
Working with multiple producers and consumers
Creating object pool with ConcurrentStack
Adding blocking and bounding with IProducerConsumerCollection
Using multiple concurrent collections to create a pipeline
Chapter 6: Synchronization Primitives
Using monitor
Using a mutual exclusion lock
Using SpinLock for synchronization
Interlocked operations
Synchronizing multiple tasks with a Barrier
Using ReaderWriterLockSlim
Using WaitHandles with Mutex
Waiting for multiple threads with CountdownEvent
Using ManualResetEventSlim to spin and wait
Using SemaphoreSlim to limit access
Chapter 7: Profiling and Debugging
Using the Threads and Call Stack windows
Using the Parallel Stacks window
Watching values in a thread with Parallel Watch window
Detecting deadlocks with the Parallel Tasks window
Measure CPU utilization with Concurrency Visualizer
Using Concurrency Visualizer Threads view
Using Concurrency Visualizer Cores view
Chapter 8: Async
Creating an async method
Handling Exceptions in asynchronous code
Cancelling an asynchronous operation
Cancelling async operation after timeout period
Processing multiple async tasks as they complete
Improving performance of async solution with Task.WhenAll
Using async for file access
Checking the progress of an asynchronous task
Chapter 9: Dataflow Library
Reading from and writing to a dataflow block synchronously
Reading from and writing to a dataflow block asynchronously
Implementing a producer-consumer dataflow pattern
Creating a dataflow pipeline
Cancelling a dataflow block
Specifying the degree of parallelism
Unlink dataflow blocks
Using JoinBlock to read from multiple data sources

What You Will Learn

  • Create a task using Parallel.Invoke, Task.Factory, and Task.Start
  • Work with declarative data parallelism using Parallel Language Integrated Query (PLINQ) and its aggregate functions
  • Perform independent operations on the member data of a collection using parallel loops
  • Coordinate the activities of multiple tasks using new lightweight synchronization primitives
  • Learn to use Visual Studio 2012 debugging and profiling capabilities related to parallel programming
  • Maintain a responsive UI using asynchronous tasks
  • Create a pipeline using multiple concurrent collections

In Detail

.NET parallel extensions brings the power of parallel and asynchronous programming to a much wider developer audience than ever before. This book will give a developer with no multithreaded development experience the ability to write highly scalable parallel applications that take advantage of modern multicore processors.If you are an experienced .NET developer who wants to put parallel extensions to work in your applications, this book is for you.

".NET 4.5 Parallel Extensions Cookbook" is a practical, hands-on guide that provides you with a number of clear step-by-step recipes that will introduce parallelism into your applications and take advantage of modern multicore processors. This book is a crash course in using the extensions, with theory and concepts kept to a minimum.

".NET 4.5 Parallel Extensions Cookbook" offers a wide-ranging presentation of parallel development concepts, and provides a working knowledge of key technologies that are important to developers who want to take advantage of multi-core architectures.

You will learn how to compose a series of producer/consumer tasks into a pipeline that can process data elements received from a real-time event stream. You will also learn how to connect the stages of pipelines together using the concurrent collections. You will learn everything you need to know to transform the multicore power found in modern processors into application performance and scalability.


Read More

Recommended for You

.Net Framework 4.5 Expert Programming Cookbook
$ 29.99
ODP.NET Developer’s Guide: Oracle Database 10g Development with Visual Studio 2005 and the Oracle Data Provider for .NET
$ 13.50
.NET Compact Framework 3.5 Data Driven Applications
$ 29.99