Showing results for Code Samples - .NET Blog

Aug 15, 2012
Post comments count0
Post likes count0

Implementing Then with Await

Stephen Toub - MSFT
Stephen Toub - MSFT

In a post a while ago, I talked about sequential composition of asynchronous operations.  Now that we have the async/await keywords in C# and Visual Basic, such composition is trivial, and async/await are indeed the recommended way to achieve such composition with these languages.However, in that post I also described a few “Then” ...

.NET Parallel Programming
Apr 26, 2012
Post comments count0
Post likes count0

Async Targeting Pack for Visual Studio 11 now available for .NET 4 and Silverlight 5

Stephen Toub - MSFT
Stephen Toub - MSFT

We’re happy to announce that you can now download an Async Targeting Pack for Visual Studio 11 that lets you target .NET 4 and Silverlight 5.  The included DLLs address the previously discussed issue of the Visual Studio 11 Beta compilers being incompatible with the AsyncCtpLibrary* DLLs from the Async CTP; with this targeting pack, you ...

.NET Parallel Programming
Mar 5, 2012
Post comments count2
Post likes count2

Implementing a simple ForEachAsync, part 2

Stephen Toub - MSFT
Stephen Toub - MSFT

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

.NET Parallel Programming
Mar 4, 2012
Post comments count0
Post likes count1

Implementing a simple ForEachAsync

Stephen Toub - MSFT
Stephen Toub - MSFT

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

.NET Parallel Programming
Mar 3, 2012
Post comments count0
Post likes count0

“The Zen of Async” at the MVP Summit 2012

Stephen Toub - MSFT
Stephen Toub - MSFT

Thanks to everyone who attended my "The Zen of Async" presentation on Thursday at the MVP Summit.  As I've had several requests, here are the slides and code for the talk. Toub_MVPSummit2012_ZenOfAsync.zip

.NET Parallel Programming
Dec 5, 2011
Post comments count0
Post likes count0

Paper :: Guide to Implementing Custom TPL Dataflow Blocks

Danny Shih
Danny Shih

TPL Dataflow includes a number of built-in, already-implemented blocks that target the most common scenarios.  Additionally, some flexibility is provided by the set of options that may be used to tweak block behaviors.  However, a developer may still choose to implement a custom block for advanced scenarios where the built-in ones are not...

.NET Parallel Programming
Dec 3, 2011
Post comments count0
Post likes count0

Coalescing CancellationTokens from Timeouts

Stephen Toub - MSFT
Stephen Toub - MSFT

In the .NET Framework 4.5 Developer Preview, you’ll find that CancellationTokenSource now has timeout support built directly into its implementation.  This makes it very easy to create a token that will automatically have cancellation requested after a particular time interval, e.g. public static CancellationToken FromTimeout(int millise...

.NET Parallel Programming
Nov 10, 2011
Post comments count0
Post likes count0

New in .NET 4.5: ThreadLocal.Values

Igor Ostrovsky - MSFT
Igor Ostrovsky - MSFT

Available since .NET 4, ThreadLocal<T> is a container that holds a separate value for every thread. In practice, ThreadLocal<T> is often convenient for storing per-thread counters, resources, or partial results. As mentioned earlier on this blog, we have been thinking about adding a Values property to enumerate over the values from all...

.NET Parallel Programming
Nov 10, 2011
Post comments count0
Post likes count0

PLINQ Queries That Run in Parallel in .NET 4.5

Igor Ostrovsky - MSFT
Igor Ostrovsky - MSFT

One interesting thing to know about PLINQ is that not all queries are guaranteed to execute in parallel (See PLINQ Queries That Run Sequentially for reference). You can think of the AsParallel method as a hint to run in parallel for query shapes that it believes will be faster. By default, PLINQ prefers to use a simple sequential algorithm over a p...

.NET Parallel Programming
Nov 10, 2011
Post comments count0
Post likes count0

Crafting a Task.TimeoutAfter Method

Joe Hoag
Joe Hoag

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 you need a way to obtain a copy or “proxy” of th...

.NET Parallel Programming