The Asyn method is a very common method that you might have experienced when using async and await, that is, you want to use them in catch blocks or finally blocks, For example, when a exception appears and you want to write the log in a file or call a service to send exception information to the server, these operations can be time-consuming. In this case, using await in the Async method in the Catch block will be helpful. This has been added to C # 6.0.
Also in the finally block, we can use await to invoke the Async method.
The following code block shows how to use them.
Public Async Task Submitdatatoserver () { try { // Submit Data } Catch { await logexceptionasync (); } finally { await closeconnectionasync (); }}
View Code
This is a common scenario for using await in catch blocks and finally blocks, and this feature will bring great convenience to developers.
C # 6.0: Using await in catch and finally