none
When Async and Await will span new thread ? RRS feed

  • Question

  • i have read a article which said Async and Await will span new thread depend on situation but not always create new thread. so i am very keen to see a example of async/await which spawn new thread. so please give me sample code of async/await which spawn new thread.

    also give me a scenario when async/await does not spawn new thread....explain with sample code.

    Sunday, December 23, 2018 5:02 PM

Answers

  • Hi Studip_inn,

    Thank you for posting here.

    Please note that the async and await keywords don't cause additional threads to be created. Async methods don't require multithreading because an async method doesn't run on its own thread. The method runs on the current synchronization context and uses time on the thread only when the method is active.

    For more details, please refer to the MSDN document.

    https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/async/

    Best Regards,m

    Wendy


    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.

    Monday, December 24, 2018 7:18 AM
    Moderator

All replies

  • Hi Studip_inn,

    Thank you for posting here.

    Please note that the async and await keywords don't cause additional threads to be created. Async methods don't require multithreading because an async method doesn't run on its own thread. The method runs on the current synchronization context and uses time on the thread only when the method is active.

    For more details, please refer to the MSDN document.

    https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/async/

    Best Regards,m

    Wendy


    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.

    Monday, December 24, 2018 7:18 AM
    Moderator
  • i have seen await keyword block the execution because await keyword hit then next statement is not executed.....does not it block UI thread ?

    if not then please share the proper explanation. thanks

    Saturday, January 12, 2019 5:25 PM