async/await Tips

There’s been some really good guidance about async/await in the past week or two.  I’ve been tinkering away at this post for a while now—based on presentations I’ve been doing, discussions I’ve had with folks at Microsoft, etc.  Now seems like a good idea to post it. First, it’s important to understand what the "async" keyword really mean.  At face value async doesn’t make a method (anonymous or member) “asynchronous”—the body of the method does that.  What it does mean is that there’s a strong possibility that the body of the method won’t entirely be evaluated when the method returns … Continue reading async/await Tips

Testing Strategies Involving Async Functions

Some things to keep in mind when writing units tests for code that use async methods: You’re not trying to test the framework’s “awaitability” and you’re not trying to test framework methods that are “awaitable”.  You want to test your code in certain isolation contexts.  One context, of course, is independent of asynchronicity–do individual units of code that don’t depend on asynchronous invocation “work”…  e.g. “Task<string> MyMethodAsync()”, you want to have a unit test that make sure this method does what it’s supposed to do (one being it returns a “valid” Task<string> object, the other being that individual side-effects occur, … Continue reading Testing Strategies Involving Async Functions

More on Async Functions

In my last post I showed .Net 1.1 and .NET 2.0 code that performed some asychronous operations.  I then showed the new syntax with “async” and “await” that did the same thing. But, I didn’t detail what’s really going on in the new syntax. If you want to know more about the details of what’s going on, read on.  If you just trust me about the previous code, you don’t have to read on 🙂 When the Click handler is executed it basically executes everything up to the first await and returns.  This allows the UI to be responsive.  The … Continue reading More on Async Functions