[C #] Stepping into the world of asynchronous programming-parsing asynchronous methods (bottom)

Source: Internet
Author: User

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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.