Asynchronous availability

Another small improvement is that you can use the await keyword inside catch and finally blocks. This was not initially allowed when this incredibly useful feature was added to C# 5. There is not a lot more to say about this. The implementation is complex, but you don't need to worry about this unless you're interested in the internals. From a developer's point of view, it just works, as in this simple example:

catch (Exception e) when (e?.Message?.Length > 0){    await Task.Delay(200);}

This feature has been improved in C# 7, so read on. You will see async and await used a lot throughout this book. Asynchronous programming is a great way of improving performance and not just from within your C# code.

Get ASP.NET Core 2 High Performance - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.