Stepping into the world of asynchronous programming-dissecting asynchronous Method (bottom) Order
Thank you for your support, this is a supplement to the world of asynchronous programming-anatomy Async Method (above), which was released yesterday.
Directory
- Exception handling
- Synchronizing the wait task in the calling method
- Asynchronously waits for a task in an async method
- Suspend operation with Task.delay ()
First, exception handling
An await expression can also use the try...catch...finally structure.
1 Internal class Program2 {3 Private Static voidMain (string[] args)4 {5 vart =Doexceptionasync ();6 t.wait ();7 8Console.WriteLine ($"{nameof (t.status)}: {T.status}");//Task Status9Console.WriteLine ($"{nameof (t.iscompleted)}: {t.iscompleted}");//Task Completion status identificationTenConsole.WriteLine ($"{nameof (t.isfaulted)}: {t.isfaulted}");//whether the task has an unhandled exception ID One A Console.read (); - } - the /// <summary> - ///Exception Action - /// </summary> - /// <returns></returns> + Private Static AsyncTask Doexceptionasync () - { + Try A { at awaitTask.run (() = {Throw NewException ();}); - } - Catch(Exception) - { -Console.WriteLine ($"{nameof (Doexceptionasync)} An exception occurred! "); - } in } -}
Figure 1-1
The parse await expression is in the try block and handles the exception in a normal manner. However, why the status in the diagram, whether the completion identity and whether the failed identity are displayed separately: Rantocompletion, True, and False? Because: The task has not been canceled, and the exception has been processed to complete!
This is the preview version, to be released after re-finishing, thank you
[C #] Stepping into the world of asynchronous programming-parsing asynchronous methods (bottom)