Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8372945
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:33:34+00:00 2026-06-09T14:33:34+00:00

Stephen Toub describes in his article "The Task-based Asynchronous Pattern" that async methods that

  • 0

Stephen Toub describes in his article "The Task-based Asynchronous Pattern" that async methods that implement the Task-based Asynchronous Pattern (TAP) may even use a specific thread such as the UI thread to execute their code. That involves that async methods are allowed to use the calling thread. In this case the async method is not really async and blocks the calling thread. Is that really allowed? It wouldn’t make sense to create an async method that blocks the calling thread, or does it?

Here is the relevant clause of Stephen’s article:

Target Environment

It is up to the TAP method’s implementation to determine where asynchronous execution occurs. The developer of the TAP method may choose to execute the workload on the ThreadPool, may choose to implement it using asynchronous I/O and thus without being bound to a thread for the majority of the operation’s execution, may choose to run on a specific thread as need-be, such as the UI thread, or any number of other potential contexts. It may even be the case that a TAP method has no execution to perform, returning a Task that simply represents the occurrence of a condition elsewhere in the system (e.g. a Task<TData> that represents TData arriving at a queued data structure).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T14:33:35+00:00Added an answer on June 9, 2026 at 2:33 pm

    The fact that the method (or part of it) may need to run on the UI thread doesn’t mean it has to block, whether you call it from the UI thread or not.

    Imagine you have a method Task DownloadAndShowData(), that asynchronously downloads some data and then shows it in the UI. To show the downloaded data on the UI, it needs to execute some code on the UI thread. You could implement it something like this:

    async Task DownloadAndShowData()
    {
        var data = await DownloadData();
        await uiSchedulerFactory.StartNew(() => ShowData(data));
    }
    

    Here, uiSchedulerFactory is a TaskFactory that executes the code on the UI thread (using SynchrnonizationContext).

    In this code, the returned Task is completed only after the data is shown in the UI, which used the UI thread. But the method itself doesn’t block. If you have a code like:

    await DownloadAndShowData();
    // some more code
    

    executing on the UI thread, what happens is that when the await is reached, the current method is “paused”, and the UI thread is freed. After the download finishes, ShowData() from above is executed on the UI thread (it can execute, there is nothing blocking the thread). After that is done, the calling method is “unpaused” and // some more code executes.

    To sum up, an async method execute some code on the UI thread (which could also be where the calling code is executing), but the async method does not block.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Edited........ sorry Sir I was referring this piece of code from Stephen Toub's article..
I am learning MVC from Stephen Walther tutorials on MSDN website. He suggests that
On page 88 of Stephen Toub's book http://www.microsoft.com/download/en/details.aspx?id=19222 There is the code private BlockingCollection<T>
On page 33 of Stephen Toub's book http://www.microsoft.com/download/en/details.aspx?id=19222 There is the code var pings
I have an Async method returning a Task. I also wish to offer a
In another question , Stephen C says: A second concern is that there are
I have an ExcelResult action result that returns Microsoft Excel documents, based off the
Stephen Walther recommends that you should provide explicit view names when you want to
I found Difference between […]Async and Begin[…] .net asynchronous APIs question but this answer
How would I go about using Stephen Celis' fantastic SCListener singleton? ( http://stephencelis.com/2009/03/02/now-i-just-need-an-audience.html )

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.