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

  • Home
  • SEARCH
  • 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 7585949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:18:09+00:00 2026-05-30T19:18:09+00:00

I have been looking at this article about using tasks in C#, and I

  • 0

I have been looking at this article about using tasks in C#, and I was wandering if someone could clear something up for me?
Doesn’t calling wait on a task defeat the purpose of creating the task, because wouldn’t it freeze up the main thread anyway because now the main thread has to wait for task to finish.
I’m assuming however that wait won’t be called straight away, so now when would you call it or how else would you know when to dispose of the task.
Assuming we have a simple case like this:

    void MyFunction()
    {
        Task t = Task.Factory.StartNew(() => { System.Threading.Thread.Sleep(5000); });
    }

if you call t.Wait() straight away the main thread will still wait 5 seconds before being able to do anything else, which kinda defeats the purpose from the users point of view, they wont be able to do anything for 5 seconds. How would you know that after 5 seconds that task has been completed? And you can dispose of t? What is a correct way of handling that?
Sorry if the question is being really naive 🙁
Thanks All 😀

  • 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-05-30T19:18:10+00:00Added an answer on May 30, 2026 at 7:18 pm

    You would probably never call Wait on a single task like this from a UI thread – as you said the whole point is not blocking the UI thread. In fact waiting on any task at all from the UI thread would be a problem.

    Waiting for task completion might however be useful to synchronize multiple tasks and return a combined result – e.g. imagine two tasks that execute a hotel query on priceline and expedia concurrently and the thread that spawned both tasks (e.g. a background thread) waiting on the outcome of both and combining the results to order the available hotels on both sites by price.

    The final result of the queries can then be dispatched back to the UI thread, typically by executing a callback or raising an event.

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

Sidebar

Related Questions

I have been looking through this fantastic article: http://blogs.zynaptiq.com/bernsee/pitch-shifting-using-the-ft/ While being fantastic, it is
I have been looking for an answer to this and could not find it
I have been looking over the internet for a while about this, but it
I have been following this useful-looking article http://collingrady.wordpress.com/2008/02/18/editing-multiple-objects-in-django-with-newforms/ . Unfortunately he doesn't hint at
I have been looking over this code for the past hour, I cant see
I have been looking to implement a custom class of : IList<ArraySegment<byte>> this will
im sorry if this was posted already i have been looking to no avail..
This might be too opinionated a question, but looking for help! I have been
I've been struggling looking for an understandable way to do this. I have four
I have been looking for a tutorial on using LDAP on an iOS device

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.