Showing 61 - 70 of 227 results for “stephen toub”

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 Foundation do with their message ...


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.Start?The Start instance ...


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...


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 get a delegate to represent an ...


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 the same thread that completed the ...


Know Thine Implicit Allocations

For .NET 4.5, we’ve invested quite a bit of effort into performance, and in particular for the Task Parallel Library (Joe Hoag wrote a good paper covering some of these improvements).  We focused such effort on TPL because it is a core component used in async programming and at a foundational level for many libraries and ...


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 to the SynchronizationContext&...


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 are exposed.  If you want to be able to &...