Showing results for Task Parallel Library - .NET Parallel Programming

Feb 11, 2012
0
2

Building Async Coordination Primitives, Part 3: AsyncCountdownEvent

Stephen Toub - MSFT
Stephen Toub - MSFT

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

Parallel ExtensionsTask Parallel Library.NET 4.5
Feb 11, 2012
0
3

Building Async Coordination Primitives, Part 2: AsyncAutoResetEvent

Stephen Toub - MSFT
Stephen Toub - MSFT

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 until it’s manually transitioned bac...

Parallel ExtensionsTask Parallel Library.NET 4.5
Feb 11, 2012
9
1

Building Async Coordination Primitives, Part 1: AsyncManualResetEvent

Stephen Toub - MSFT
Stephen Toub - MSFT

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 to build simple coordination primitive...

Parallel ExtensionsTask Parallel Library.NET 4.5
Feb 8, 2012
0
3

Potential pitfalls to avoid when passing around async lambdas

Stephen Toub - MSFT
Stephen Toub - MSFT

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

Parallel ExtensionsTask Parallel Library.NET 4.5
Feb 7, 2012
0
1

When “ExecuteSynchronously” doesn’t execute synchronously

Stephen Toub - MSFT
Stephen Toub - MSFT

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

Parallel ExtensionsTask Parallel Library.NET 4
Feb 6, 2012
0
0

FromAsync(asyncResult, …) vs FromAsync(beginMethod, …)

Stephen Toub - MSFT
Stephen Toub - MSFT

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” as the first pa...

Parallel ExtensionsTask Parallel Library.NET 4
Jan 21, 2012
0
0

Await, SynchronizationContext, and Console Apps: Part 2

Stephen Toub - MSFT
Stephen Toub - MSFT

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

Parallel ExtensionsTask Parallel Library.NET 4
Jan 20, 2012
0
0

Implementing a SynchronizationContext.SendAsync method

Stephen Toub - MSFT
Stephen Toub - MSFT

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

Parallel ExtensionsTask Parallel Library.NET 4
Jan 20, 2012
4
3

Await, SynchronizationContext, and Console Apps

Stephen Toub - MSFT
Stephen Toub - MSFT

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 should run back on that same UI thread. ...

Parallel ExtensionsTask Parallel Library.NET 4.5
Jan 14, 2012
0
0

FAQ on Task.Start

Stephen Toub - MSFT
Stephen Toub - MSFT

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

Parallel ExtensionsTask Parallel Library.NET 4