.NET Parallel Programming

All about Async/Await, System.Threading.Tasks, System.Collections.Concurrent, System.Linq, and more…

Debugger display of PLINQ queries

Sometimes very simple additions to an API or implementation make me happy.  One such nicety in the CTP of PLINQ is the implementation of ToString on the concrete types that represent query operators.  These implementations provide a textual representation of the query structure,

Parallel Extensions on .NET Rocks

Joe Duffy, our dev lead, appeared on the 12/25/07 edition of .NET Rocks!, speaking about Parallel Extensions and the Task Parallel Library:

“Carl and Richard talk to Microsoft’s Joe Duffy about the Task Parallel Library, which promises to make multi-threaded programming easier for us all.”

F# and the Task Parallel Library

Over on his blog, Don Syme has a post about F# and Parallel Extensions:

“Over the coming year I expect we’ll be seeing this library used very widely from F#, and we’ll eventually be using the TPL as a key underlying technology for F# asynchronous workflows.

LINQ 101, “Parallelism Blockers,” and PLINQ

PLINQ is a very cool technology, and I believe it will prove useful for parallelizing operations in a wide range of important scenarios.  Moreover, I believe that the programming model it provides will enable a wide-range of developers to easily take advantage of concurrency in their applications. 

Another Parallel Extensions screencast

Daniel Moth
is on a roll.  Two weeks ago he created three great overview screencasts for Parallel Extensions to the .NET Framework.  Today, he released a fourth video, covering the Task and TaskManager classes.  Thanks, Daniel!  We’ll get this added to the MSDN Parallel Computing developer center soon,

Code Snippets for Parallel.For and Parallel.ForEach

Introduced in Visual Studio 2005, Code Snippets allow you to quickly insert reusable blocks of code into your project.  For example, if you want to quickly write a for loop in C#, you can simply type “for” into your code file, and IntelliSense shows you the “for”

Parallelizing a query with multiple “from” clauses

Consider a simplified version of Luke Hoban’s LINQ ray tracer
var Xs = Enumerable.Range(1, screenWidth);

var Ys = Enumerable.Range(1, screenHeight);

 

var sequentialQuery =  

from x in Xs

from y in Ys

select new { X = x, Y = y,

Parallel Extensions and Silverlight 2.0

From time to time, we get a question about whether we intend for Parallel Extensions to target Silverlight.  The simple answer is: Not Yet.
Here’s a more complete answer: Not for Silverlight 2.0, at least.  Rich Lander from the CLR team described the Silverlight compatibility story very nicely over on his blog. 

Give Feedback Through the Connect site

Have you found any bugs, unknown issues (vs. known issues), or any wish list items?  Go to our Connect site, sign up for the Parallel Extensions to the .NET Framework connection, and start giving us direct feedback. 

 

While the blog comments and forums are a great way to raise concerns,

MSDN Forums

There are some great discussions going on over at the Parallel Extensions forum on MSDN.  Download the CTP, try out the bits, head on over to the forums, and get involved!  We’d love to hear from you.

Uncategorized

New Task APIs in .NET 4.6

There are several nice API-level enhancements to the Task Parallel Library in .NET 4.6, which you can grab a preview of as part of the Visual Studio 2015 CTP.
Task.From*
.NET 4.5 had a Task.FromResult method.  This method makes it quick and easy to manufacture a new Task for a known result value,

.NET memory allocation profiling and Tasks

The .NET Framework blog published this morning a guest post from yours truly on .NET Memory Allocation Profiling with Visual Studio 2012.  As you’re trying to improve the performance, throughput, and memory usage of code that uses Tasks, the described profiler in Visual Studio can be a valuable tool in your tool belt (of course,

Tasks, Monads, and LINQ

A few years back, Wes Dyer wrote a great post on monads, and more recently, Eric Lippert wrote a terrific blog series exploring monads and C#. In that series, Eric alluded to Task<TResult> several times, so I thought I’d share a few related thoughts on Task<TResult>

“Invoke the method with await”… ugh!

I can be a bit sensitive when it comes to language and how concepts are conveyed.  I think it’s important to be accurate, even if not precise, when describing what something is or how to use it, as otherwise the folks to whom you’re communicating can easily form the wrong mental model for that thing. 

MVP Summit presentation on async

Lucian Wischik and I presented an “async clinic” at the MVP Summit in Bellevue this week.  The async/await keywords in C# and Visual Basic drastically simplify asynchronous programming, but that of course doesn’t mean that using them is without any gotchas: the goal of the discussion was to highlight some of the key areas in which we see developers struggling with asynchronous development and to help provide guidance on avoiding and overcoming those roadblocks. 

Psychic Debugging of Async Methods

These days it’s not uncommon for me to receive an email or read a forum post from someone concerned about a problem they’re experiencing with an async method they’ve written, and they’re seeking help debugging the issue.  Sometimes plenty of information about the bug is conveyed,

Cooperatively pausing async methods

Recently I was writing an app that processed a bunch of files asynchronously.  As with the Windows copy file dialog, I wanted to be able to provide the user with a button that would pause the processing operation.
To achieve that,

C# memory model articles

Igor Ostrovsky is one of the minds behind the parallel programming support in the .NET Framework.  Igor’s recently written a great set of articles for MSDN Magazine to cover “The C# Memory Model in Theory and Practice“.  Part 1 is available now in the December 2012 issue,

PLINQ and Int32.MaxValue

In both .NET 4 and .NET 4.5, PLINQ supports enumerables with up to Int32.MaxValue elements.  Beyond that limit, PLINQ will throw an overflow exception.  LINQ to Objects itself has this limitation with certain query operators (such as the indexed Select operator which counts the elements processed),

How do I cancel non-cancelable async operations?

This is a question I hear relatively frequently:

“I have an async operation that’s not cancelable.  How do I cancel it?”

The construction of the question often makes me chuckle, but I understand and appreciate what’s really being asked.  The developer typically isn’t asking how to cancel the operation itself (if they are asking that,