Talk: The New Async Design Patterns
Async involves some new concepts. They're not difficult; just unfamiliar. Over the past year I've been watching how people use it. This talk distils out the three top async patterns and anti-patterns.
- Async void is for top-level event-handlers only, and event-like things. Don't use it elsewhere in your code.
- You can wrap events up in Task-returning APIs and await them. This can dramatically simplify code.
- It's crucial to distinguish CPU-bound work (should be done on threadpool) from IO-bound work (which needn't).
If you understand the basic flow of control in an async method, then those three points all fall naturally into place.
- I gave this talk at Techready16 in Seattle, USA on 2013.02.05
PS. The first anti-pattern is "async void". People of course ask: "If it's so wrong, then why did you allow it?" That's a good question. I'll write a blog post solely on this question next week.