c# what is Async function and ConfigureAwait(false) does

T.Zacks 3,996 Reputation points
2022-08-30T09:59:55.107+00:00

after searching google i saw some one is saying ConfigureAwait(false) is allow to run code on thread pool thread instead of current thread. is it true?

when to use ConfigureAwait(false) ? and when to use ConfigureAwait(true) ?

looking for a sample code which show me that ConfigureAwait(false) running code in thread pool thread instead of current thread.

Thanks

Developer technologies C#
0 comments No comments
{count} votes

Accepted answer
  1. Jack J Jun 25,296 Reputation points
    2022-08-31T09:04:14.52+00:00

    @T.Zacks ,Welcome to Microsoft Q&A,
    i saw some one is saying ConfigureAwait(false) is allow to run code on thread pool thread instead of current thread. is it true?

    Yes, ConfigureAwait(false) is allow to run code on thread pool thread. Whether to generate a thread pool depends on ifr you use continuation. If the first task you call ConfigureAwait on has already completed, the code will continue to execute synchronously, otherwise it will generate the new thread from the thread-pool.

    Please refer to the answer from the stackoverflow, which also has a code example to explain it.

    when to use ConfigureAwait(false) ? and when to use ConfigureAwait(true) ?

    The following blog answers your question.

    https://devblogs.microsoft.com/dotnet/configureawait-faq/

    Best Regards,
    Jack


    If the answer is the right solution, please click "Accept Answer" and upvote it.If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.