In a contest between async proper, Task.Run, and dedicated threads, who will win? Let’s gather some data points for a specific scenario and find out! Today’s benchmark will make use of a trivial single process WCF named pipes application using…
ContinueWith slowly
Previously I discussed the hidden costs of ‘async’ and even discussed a benchmark within the comments. Here is another interesting benchmark on a case that I’ve seen come up a few times. Which of these do you think is faster?…
SSD and … sync I/O?
Walter Bright (via Andrei Alexandrescu) says, “Measuring gives you a leg up on experts who are too good to measure.” Today I’ll present some measurements that might be a bit surprising. In the old days of mechanical spinning disks, the…
Async in the wild: WCF
WCF (client) is open source. An interesting side effect of this development is the opportunity for async enthusiasts to pore over some production-ready async code. Since WCF was released even before .NET 3.5, it has several clever patterns for sensibly…
Orchestrating race conditions
Many a programmer has struggled with unit tests and those pesky race conditions that are seemingly immune to them. Is it even possible to verify concurrency correctness using TDD? I am going to tell you that it is — sometimes.…
Laziness is a virtue
Sometimes you want lazy initialization but your initialization function is asynchronous. Stephen Toub wrote about this conundrum years ago on the pfxteam blog. The solution as he describes it is fairly straightforward — use Lazy<T> combined with Task<T> and you’re…
Object Mother and Tasks
In a previous post “Fluent async testing,” I introduced a sample library to beautify unit tests relying on Task-based assertions. Tests for this type of library typically make heavy use of “canned Tasks” to ensure every case is handled correctly.…
Wake up!
In Effective Unit Testing: A guide for Java developers, author Lasse Koskela writes about the scourge of the sleeping snail — slow tests littered with calls to Thread.sleep. His suggested alternative is perfectly sound and practical: turn nondeterministic waiting into…
From sync to async: SQL
Previously I discussed some common sync scenarios using network and file I/O and how they can be migrated to modern async patterns. Today I have an addendum about asynchronous programming with SQL connections. Let me start by saying that async…
Interfaces: sync or async?
Given an extensible interface, how should one decide whether to define synchronous or asynchronous methods? (Note that in this case I mean interface in the general software engineering sense, so feel free to substitute base class, exported DLL function, function…