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 “await” such asynchronous… Read more

Released! Parallel Extensions to the .NET Framework June 2008 CTP

We’re very excited to announce our 2nd Community Technology Preview (CTP) for Parallel Extensions to the .NET Framework 3.5.  We released the Dec07 CTP on 11/29/2007, and from that we have received a lot of feedback from the community and customers.  While you have been using our bits, participating in our forums, sharing your insights… Read more

What’s new in Beta 1 for the Task Parallel Library? (Part 1/3)

Related Posts: What’s new in Beta 1 for the Task Parallel Library? (Part 2/3) What’s new in Beta 1 for the Task Parallel Library? (Part 3/3) The Task Parallel Library (TPL) has come a long way since its inception.  Over the course of several CTPs, it has evolved to be an important and central new… Read more

What’s new in Beta 1 for the Task Parallel Library? (Part 3/3)

Related posts: What’s new in Beta 1 for the Task Parallel Library? (Part 1/3) What’s new in Beta 1 for the Task Parallel Library? (Part 2/3) So what else is new in TPL for Beta 1 (finally)?  In the last post, we mentioned that TaskFactory offers more static helper methods than just StartNew.  In this… Read more

ExecutionContext vs SynchronizationContext

I’ve been asked a few times recently various questions about ExecutionContext and SynchronizationContext, for example what the differences are between them, what it means to “flow” them, and how they relate to the new async/await keywords in C# and Visual Basic.  I thought I’d try to tackle some of those questions here. WARNING: This post… Read more

Getting random numbers in a thread-safe way

It’s very common in a parallel application to need random numbers for this or that operation.  For situations where random numbers don’t need to be cryptographically-strong, the System.Random class is typically a fast-enough mechanism for generating values that are good-enough.  However, effectively utilizing Random in a parallel app can be challenging in a high-performance manner…. Read more

Should I expose asynchronous wrappers for synchronous methods?

Lately I’ve received several questions along the lines of the following, which I typically summarize as “async over sync”: In my library, I have a method “public T Foo();”.  I’m considering exposing an asynchronous method that would simply wrap the synchronous one, e.g. “public Task<T> FooAsync() { return Task.Run(() => Foo()); }”.  Is this something… Read more

Cooperatively pausing async methods

Recently I was writing an app that processed a bunch of files asynchronously.  As with the Windows copy file dialog, I wanted to be able to provide the user with a button that would pause the processing operation. To achieve that, I implemented a simple mechanism that would allow me to pass a “pause token”… Read more

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… Read more

New Task APIs in .NET 4.6

There are several nice API-level enhancements to the Task Parallel Library in .NET 4.6, which you can grab a preview of as part of the Visual Studio 2015 CTP. Task.From* .NET 4.5 had a Task.FromResult method.  This method makes it quick and easy to manufacture a new Task for a known result value, and is… Read more