Posts by this author

Jan 20, 2012
0
0

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

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

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

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

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

Parallel ExtensionsTask Parallel Library.NET 4
Dec 15, 2011
0
0

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

Parallel ExtensionsTask Parallel Library.NET 4.5
Dec 3, 2011
0
0

Coalescing CancellationTokens from Timeouts

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

Parallel Extensions.NET 4.5Code Samples
Nov 1, 2011
0
0

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 Studio and the .NET Fr...

Task Parallel Library.NET 4Async
Oct 24, 2011
0
0

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(…); ...

Parallel ExtensionsTask Parallel Library.NET 4.5
Oct 24, 2011
0
1

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 power is complexity.  You need to know w...

Parallel ExtensionsTask Parallel Library.NET 4
Oct 3, 2011
0
0

New articles on async/await in MSDN Magazine

The October 2011 issue of MSDN Magazine is now available online.  In it, you can find three articles about the new async/await features of C# and Visual Basic.  While the articles can stand alone, they were written with each other in mind in order to provide a 1-2-3 on-ramp into the world of asynchronous programming with these new languag...

.NET 4.5AsyncArticle Summary
Oct 2, 2011
0
0

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”); } } Now conside...

Parallel ExtensionsTask Parallel Library.NET 4.5