Practical .NET

Book Review: .NET 4.5 Parallel Extensions Cookbook

Bryan Freeman's book on creating asynchronous applications does a great job of explaining the technology the .NET Framework provides for creating asynchronous applications. It's not as successful in providing recipes for business applications, however.

In the bad old days, if you wanted to create an application that was guaranteed to have bugs that you would never track down, you created a multi-threaded application. You had only a limited range of tools (really, just the Thread object), and it was your responsibility to manage them. The best answer to "How do I create a multi-threaded application?" was "Just say 'No.'"

The current versions of the .NET Framework provide a more sophisticated set of tools for creating what we now call asynchronous applications. Applications that use parallel processing are still dangerous to create. The tools provided in .NET, however, make it at least possible for mere mortals like you and me to reliably build applications that do more than one thing at a time.

This set of tools creates the need for books like Bryan Freeman's .NET 4.5 Parallel Extensions Cookbook from Packt Publishing. Bryan provides a thorough review of the tools and technologies included in the .NET Framework to create responsive applications that take advantage of both the Windows multi-threading capability and today's multi-core computers.

A recipe book is intended to provide solutions to common problems. The idea behind a recipe book is that when faced with some problem, you can open the book, scan the table of contents until you find your problem, and then apply the solution provided. Freeman's solutions are laid out well, use the technology well and look reliable.

Throughout the book, Freeman does an excellent job of explaining how to use the tools the .NET Framework provides. Sometimes, Freeman's enthusiasm for the technology carries the book away: In Chapter 8, he includes a discussion of the context created for async operations in Console applications that, as he points out, you don't really need to know because the .NET Framework takes care of it.

Recipes for Asynchronous Processing
There are some fundamental issues with recipe books. A recipe book assumes that you're already familiar with the problem domain. In cooking, a recipe isn't any good to you if you don't recognize the need to cook or know how to work with a stove, know how to get groceries and so on. No matter how good Freeman's book is, it's not going to be the only reference on asynchronous processing that you'll need. Freeman's book has to assume that you can recognize when you need an asynchronous solution, for example.

But even though this is a recipe book, Freeman manages to cover some of those higher-level issues. Chapter 3, for example, includes a reference to the overhead involved in implementing parallelism, pointing out that a parallel solution has to generate enough benefits to offset that overhead. Freeman returns to this topic throughout the chapter to show how to reduce that overhead and emphasize the conditions when a sequential solution would be a better choice than an asynchronous one.

In fact, Chapter 3 is a little out of place in a recipe book, as suggested by its title: "Learning Concurrency with Parallel Loops." The chapter is really a tutorial on writing code with Parallel.ForEach, starting with a minimum implementation and working up to solutions that incorporate more features.

Strong Technology Focus
Unfortunately, few of the recipes reflect the kind of application you probably have to write. Virtually all of the recipes are implemented as Console applications (I often believe that only people writing technical books and training courses actually create Console applications). As someone who primarily creates ASP.NET applications, I was disappointed that none of the recipes directly addressed how to integrate parallel processing into Web applications (there is a recipe for accessing Web-based resources, but it uses the HttpClient rather than a Web Service proxy -- not the typical scenario). Windows Services are also ignored, though they're often home to parallel processes.

In the same vein, all of the sample code revolves around processing arrays of integers or parsing text downloaded from gutenburg.org. Examples more relevant to business application developers might have been a better choice in tying these tools to the problems developers face (processing large numbers of objects retrieved from a database using Entity Framework or ADO.NET, for example).

This reflects the one real issue readers may have with this recipe book: The focus is on the technology, rather than on typical problems that developers face when writing applications. The table of contents, for example, is built around the tools rather than business problems. Chapter 9 is called "DataFlow Library" rather than "Reliably Building Applications with Multiple Concurrent Processes." This means that if you don't know what the DataFlow library is to be used for, you won't know what problems this chapter solves. Chapter 9 also begins by discussing the objects that make up the DataFlow library, rather than discussing the kind of business problem that the objects solve.

If you're looking for a practical introduction to using the available tools that focuses on the technology issues, Freeman's book is for you. You'll also need to read up on how to spot opportunities to use parallel processing and how to architect concurrent solutions, as you would with any recipe book. To apply these solutions to typical business problems, you'll need to see the connection between the technology-focused examples in this book and the real-world problems you're dealing with in your job.

About the Author

Peter Vogel is a system architect and principal in PH&V Information Services. PH&V provides full-stack consulting from UX design through object modeling to database design. Peter tweets about his VSM columns with the hashtag #vogelarticles. His blog posts on user experience design can be found at http://blog.learningtree.com/tag/ui/.

comments powered by Disqus

Featured

  • AI for GitHub Collaboration? Maybe Not So Much

    No doubt GitHub Copilot has been a boon for developers, but AI might not be the best tool for collaboration, according to developers weighing in on a recent social media post from the GitHub team.

  • Visual Studio 2022 Getting VS Code 'Command Palette' Equivalent

    As any Visual Studio Code user knows, the editor's command palette is a powerful tool for getting things done quickly, without having to navigate through menus and dialogs. Now, we learn how an equivalent is coming for Microsoft's flagship Visual Studio IDE, invoked by the same familiar Ctrl+Shift+P keyboard shortcut.

  • .NET 9 Preview 3: 'I've Been Waiting 9 Years for This API!'

    Microsoft's third preview of .NET 9 sees a lot of minor tweaks and fixes with no earth-shaking new functionality, but little things can be important to individual developers.

  • Data Anomaly Detection Using a Neural Autoencoder with C#

    Dr. James McCaffrey of Microsoft Research tackles the process of examining a set of source data to find data items that are different in some way from the majority of the source items.

  • What's New for Python, Java in Visual Studio Code

    Microsoft announced March 2024 updates to its Python and Java extensions for Visual Studio Code, the open source-based, cross-platform code editor that has repeatedly been named the No. 1 tool in major development surveys.

Subscribe on YouTube