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

Paper :: Guide to Implementing Custom TPL Dataflow Blocks

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 sufficient.  Zlatko… Read more

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 millisecondsDue) {     return new CancellationTokenSource(millisecondsDue).Token; } Under the covers… Read more