It stands to reason that DisposeAsync would be the asynchronous counterpart of IDisposable.Dispose. However, I recommend that you do not use the Dispose pattern for asynchronous cleanup. Why not? First off, an async version of Dispose would not work properly…
Async fixed concurrency workflows
In the previous post, I mentioned async fixed concurrency workflows as providing the best balance between resource utilization, latency, and throughput. Let’s explore two ways to build such a workflow. Single-threaded workflow The first design we will look at involves…
Designing for fixed concurrency
Consider a simple load test which is trying to maintain a constant stream of parallel requests against a server. That is, at any given moment the server should be handling, say, 100 concurrent requests. The exact number is not important,…
Async exclusive lock: integration test
In the previous post, I introduced my ExclusiveLock. In the typical TDD style, I ended up with a correct single-threaded implementation. However, as soon as I added parallelism and exception tracking to the basic integration test, I began hitting exceptions…
Building an async exclusive lock
The Monitor class is useful for establishing critical sections in your .NET code. However, this is of no use in asynchronous scenarios for at least two reasons: Monitor has thread affinity, meaning the same thread must acquire and release. Monitor…
MemoryChannel integration test
In a previous post, I discussed the concurrency issues with the initial MemoryChannel implementation and how unit tests were insufficient to uncover them. I came up with these basic requirements/invariants to guide my integration test design: Data from separately sent…
MemoryChannel and concurrency
In a previous post, I described MemoryChannel and how I used TDD to implement it. After the 25th commit, 20 unit tests later, I had a fully functional but single-threaded implementation. Simply by inspection, I knew that this code would…
TDD + async: Introducing MemoryChannel
Can you use test-driven development and unit testing with asynchronous code? Yes, with a few caveats. Above all, unit tests should be deterministic and fast. This means you should stick to single-threaded workflows as much as possible and never sleep.…
Async coding guidelines
Here are some basic guidelines for writing async C# code (.NET 4.5+). These are adapted from guidance I have given my colleagues and should be useful primarily to those new to Task, async/await, and the like. To keep things interesting,…