Parallel Programming with .NET

All about System.Threading, System.Threading.Tasks, System.Collections.Concurrent, System.Linq, and more...

Browse by Tags

Tagged Content List
  • Blog Post: 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. ...
  • Blog Post: Building Async Coordination Primitives, Part 6: AsyncLock

    Last time, we looked at building an AsyncSemaphore .  Here, we’ll look at building support for an async mutual exclusion mechanism that supports scoping via ‘using’. As mentioned in the previous post, semaphores are great for throttling and resource management.  You can give a semaphore an...
  • Blog Post: 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...
  • Blog Post: Building Async Coordination Primitives, Part 4: AsyncBarrier

    Last time, we looked at building an AsyncCountdownEvent .  At the end of the post, I highlighted a common pattern for using such a type, which is for all of the participants to signal and then wait for all of the other participants to signal as well.  This kind of synchronization is typically...
  • Blog Post: 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...
  • Blog Post: Building Async Coordination Primitives, Part 2: AsyncAutoResetEvent

    In my last post, I discussed building an asynchronous version of a manual-reset event .  This time, we’ll build an asynchronous version of an auto-reset event. A manual-reset event is transitioned to the signaled state when requested to do so (i.e. calling Set()), and then it remains in that state...
  • Blog Post: Building Async Coordination Primitives, Part 1: AsyncManualResetEvent

    The Task-based Async Pattern (TAP) isn’t just about asynchronous operations that you initiate and then asynchronously wait for to complete.  More generally, tasks can be used to represent all sorts of happenings, enabling you to await for any matter of condition to occur.  We can even use Tasks...
  • Blog Post: Potential pitfalls to avoid when passing around async lambdas

    One of the really useful capabilities of the new async methods feature in C# and Visual Basic is the ability to write async lambdas and anonymous methods (from here on in this post, I’ll refer to both of these as async lambdas, since the discussion applies equally to both).  This allows you to easily...
  • Blog Post: When “ExecuteSynchronously” doesn’t execute synchronously

    When creating a task continuation with ContinueWith, developers have the opportunity to provide a TaskContinuationOptions enum value, which could include the TaskContinuationOptions.ExecuteSynchronously flag.  ExecuteSynchronously is a request for an optimization to run the continuation task on...
  • Blog Post: FromAsync(asyncResult, …) vs FromAsync(beginMethod, …)

    The Task Parallel Library (TPL) provides a set of “ FromAsync ” helper methods that create a Task or a Task<TResult> to represent an invocation of an APM method pair, i.e. BeginXx / EndXx.  There are, however, two different flavors among these overloads: ones that accept an IAsyncResult “asyncResult...
  • Blog Post: Await, SynchronizationContext, and Console Apps: Part 2

    Yesterday, I blogged about how you can implement a custom SynchronizationContext in order to pump the continuations used by async methods so that they may be processed on a single, dedicated thread.  I also highlighted that this is basically what UI frameworks like Windows Forms and Windows Presentation...
  • Blog Post: Implementing a SynchronizationContext.SendAsync method

    I recently saw two unrelated questions, the answers to which combine to form a potentially useful code snippet. The first question was about SynchronizationContext. SynchronizationContext provides a Post method, which asynchronously schedules the supplied delegate and object state to be executed according...
  • Blog Post: Await, SynchronizationContext, and Console Apps

    When I discuss the new async language features of C# and Visual Basic, one of the attributes I ascribe to the await keyword is that it “tries to bring you back to where you were.” For example, if you use await on the UI thread of your WPF application, the code that comes after the await completes...
  • Blog Post: FAQ on Task.Start

    Recently I’ve heard a number of folks asking about Task.Start, when and when not to use it, how it behaves,and so forth.  I thought I’d answer some of those questions here in an attempt to clarify and put to rest any misconceptions about what it is and what it does. 1. Question: When can I use Task...
  • Blog Post: Awaiting Socket Operations

    The System.Net.Sockets.Socket class in .NET exposes multiple sets of asynchronous methods that perform the same basic operations but that are exposed with different patterns. The first set follows the APM pattern, where for a synchronous method like Receive, the BeginReceive and EndReceive methods...
  • Blog Post: Paper :: TPL Performance Improvements in .NET 4.5

    We invested a lot of time into making parallel programming “just faster” for .NET 4.5.  You’ve already seen some neat tricks to ConcurrentDictionary .  There’s a lot more to say about improving the performance of the Task Parallel Library, and Joe Hoag has a written an excellent paper on the...
  • Blog Post: Crafting a Task.TimeoutAfter Method

    Imagine that you have a Task handed to you by a third party, and that you would like to force this Task to complete within a specified time period. However, you cannot alter the “natural” completion path and completion state of the Task, as that may cause problems with other consumers of the Task. So...
  • Blog Post: Updated Async CTP

    In April, we released the Async CTP Refresh, and since then we've seen fantastic adoption of the technology. We've also seen the technology landscape evolve. Windows Phone 7.5, aka "Mango", was released. Silverlight 5 has had both a Beta and an RC release. And there have been multiple patches to Visual...
  • Blog Post: When at last you await

    When you start using async methods heavily, you’ll likely see a particular pattern of composition pop up from time to time.  Its structure is typically either of the form: async Task FooAsync() {     … // some initialization code without awaits      await BarAsync...
  • Blog Post: Task.Run vs Task.Factory.StartNew

    In .NET 4, Task.Factory.StartNew was the primary method for scheduling a new task.  Many overloads provided for a highly configurable mechanism, enabling setting options, passing in arbitrary state, enabling cancellation, and even controlling scheduling behaviors.  The flip side of all of this...
  • Blog Post: Keeping Async Methods Alive

    Consider a type that will print out a message when it’s finalized, and that has a Dispose method which will suppress finalization: class DisplayOnFinalize : IDisposable { public void Dispose() { GC.SuppressFinalize(this); } ~DisplayOnFinalize() { Console.WriteLine(“Finalized”...
  • Blog Post: Don’t Forget To Complete Your Tasks

    “Don’t forget to complete your tasks.” That guidance may sound trivial and silly, but I recently saw it as a source of a bug in software written by some very smart folks, and thus thought this would be a good opportunity to remind folks of the imperative. Tasks represent a promise...
  • Blog Post: Task Exception Handling in .NET 4.5

    For the .NET Framework 4.5 Developer Preview, a lot of work has been done to improve the Task Parallel Library (TPL), in terms of functionality, in terms of performance, and in terms of integration with the rest of the .NET Framework. With all of this work, we’ve strived for a very high compatibility...
  • Blog Post: Updated TPL Dataflow CTP

    It’s been a few months since April when we last released a Community Technology Preview (CTP) of System.Threading.Tasks.Dataflow.dll, aka “TPL Dataflow”. Today for your programming pleasure, we have another update. As mentioned in “ What’s New for Parallelism in .NET...
  • Blog Post: What’s New For Parallelism in .NET 4.5

    .NET 4 and Visual Studio 2010 saw the introduction of a wide range of new support for parallelism: the Task Parallel Library (TPL), Parallel LINQ (PLINQ), new synchronization and coordination primitives and collections (e.g. ConcurrentDictionary), an improved ThreadPool for handling parallel workloads...
Page 1 of 5 (119 items) 12345