none
Difference between async and await in c#? RRS feed

All replies

  • Hi Anas ,

    Usually, the program we write is synchronous, running from the first line of code to the last sentence of the program in sequence. The core of asynchronous programming is to use multi-threads, by allowing different threads to perform different tasks, so as to achieve asynchronous programming.

    The characteristics of async/await are closely related to Task, so it is necessary to fully understand the use of Task before understanding async/await.

    Task will not create a new thread immediately every time when it executes, but will go to the CLR thread pool to see if there are any idle threads. In some cases, it will take a thread to process the request and then put the thread back into the thread pool after processing the request. And that thread will not be immediately revoked, but will be set to an idle state for the thread pool to schedule again, thus reducing overhead and increasing utilization.

    Asynchronization is mainly achieved by await. If a method declared async does not use keyword 'await' , it will be treated as a synchronization method when it is executed. At this time, the compiler will also throw a warning that await is not used in the method and will be used as a synchronization method.

    I hope it will help you.

    Best regards,
    Julia

    MSDN Community Support Please remember to click Mark as Answer ,the responses that resolved your issue, and to click Unmark as Answer if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, February 8, 2019 7:19 AM
  • Hello,

    I would recommend reading though Stephen Clearly's blog post.

    This series

    https://blog.stephencleary.com/2013/01/async-oop-0-introduction.html

    Then this post

    https://blog.stephencleary.com/2012/02/async-and-await.html


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Friday, February 8, 2019 11:14 AM
    Moderator
  • Hi 

    Is your problem solved? If so, please post "Mark as answer" to the appropriate answer, so that it will help other members to find a solution quickly if they face a similar issue.

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Tuesday, February 19, 2019 8:01 AM
    Moderator