.NET Parallel Programming

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

Implementing a simple ForEachAsync, part 2

After my previous post, I received several emails and comments from folks asking why I chose to implement ForEachAsync the way I did.  My goal with that post wasn’t to prescribe a particular approach to iteration, but rather to answer a question I’d received… obviously, however, I didn’t provide enough background...

Implementing a simple ForEachAsync

Jon Skeet recently asked me how I might go about implementing the following “asynchronous ForEach” behavior: Given what we now know about SemaphoreSlim from my previous post, here’s one way to achieve this: public static Task ForEachAsync<TSource, TResult>(     this IEnumerable<TSource...

Building Async Coordination Primitives, Part 7: AsyncReaderWriterLock

In my last past, we looked at building an AsyncLock in terms of an AsyncSemaphore.  In this post, we’ll build a more advanced construct, an asynchronous reader/writer lock.An asynchronous reader/writer lock is more complicated than any of the previous coordination primitives we’ve created.  It also involves more policy, ...

Building Async Coordination Primitives, Part 5: AsyncSemaphore

In my last few posts, I covered building an AsyncManualResetEvent, an AsyncAutoResetEvent, an AsyncCountdownEvent, and an AsyncBarrier.  In this post, I’ll cover building an AsyncSemaphore class.Semaphores have a wide range of applicability.  They’re great for throttling, for protected access to a limited set of resources...

Building Async Coordination Primitives, Part 3: AsyncCountdownEvent

In my last two posts, I discussed building AsyncManualResetEvent and AsyncAutoResetEvent coordination primitives.  In this post, I’ll build on that to create a simple AsyncCountdownEvent.A countdown event is an event that will allow waiters to complete after receiving a particular number of signals.  The “countdown&rdquo...