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 6911813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:00:21+00:00 2026-05-27T09:00:21+00:00

After reading up on inlining in the TPL from sources like here , I

  • 0

After reading up on inlining in the TPL from sources like here, I got the impression that a call to Task.Wait() will start a task that hasn’t yet begun (at least using the default scheduler). However, writing up a quick demo like:

var taskB = new Task(
  () =>
      {
        Console.WriteLine("In TaskB");
        System.Threading.Thread.Sleep(5000);
        Console.WriteLine("Leaving TaskB");
      });

var taskA = new Task(
  () =>
      {
        Console.WriteLine("In TaskA");
        System.Threading.Thread.Sleep(500);
        Console.WriteLine("Waiting on TaskB");
        taskB.Wait();
        Console.WriteLine("Leaving TaskA");
        });

taskA.Start();
taskA.Wait();

Causes a deadlock. TaskA gets to the taskB.Wait() line, but taskB is never started. I haven’t messed with the scheduler or anything, so I’m not really sure why the .Wait() call on taskB wouldn’t cause it to start.

  • 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-27T09:00:22+00:00Added an answer on May 27, 2026 at 9:00 am

    Wait() does not cause a task to Start(). If you call Wait() on an unstarted task, it will wait for it to begin and complete until it completes, the wait timed out or the wait is cancelled. Since your call to Wait() does not contain a cancellation token or timeout, it’s an infinite for the task to complete.

    I think what’s confusing you from the blog is this line:

    However, if it hasn’t started executing, Wait may be able to pull the
    target task out of the scheduler to which it was queued and execute
    it inline on the current thread.

    The key here is the phrase “hasn’t started executing”. This does not mean that Start() was not called, but that Start() was called, which schedules the task and makes it ready to execute, but the task hasn’t begun to execute.

    Start() is necessary to schedule a task for execution, it doesn’t immediately begin execution. That’s the main point of that blurb. If the task is ready to go but not scheduled, it may be inlined. But it won’t start a task that hasn’t even been scheduled.

    If you look at TaskStatus in the MSDN (See here) you see the following values:

    • Created
    • WaitingForActivation
    • WaitingToRun
    • Running
    • WaitingForChildrenToComplete
    • RanToCompletion
    • Canceled
    • Faulted

    When you create the task (with new or factory), it is in Created state. Nothing happens to a task in this state. Once it is started, then it moves to WaitingForActivation and so on, at THIS point until it reaches Running, its possible according to that blog that it could be inlined.

    So, long story short, creating a task just puts it in Created state and won’t make it start if Wait() is called. Make sense?

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

Sidebar

Related Questions

After reading Eric Lippert’s answer I got the impression that await and call/cc are
After reading the documentation for MySQL Workbench I got the impression that it's possible
After reading some posts like this one: Choose File Dialog It appears that Android
After reading about CCR : http://www.infoq.com/news/2008/12/CCR I get the impression that it does pretty
After reading an article on REST (Restful Grails), I have gotten the impression that
After reading tons of documentation and questions from here I'm still stuck with the
After reading this answer: best way to pick a random subset from a collection?
After reading the tips from this great Nettuts+ article I've come up with a
After reading the answer to this question , I learned that SFINAE can be
After reading a question on @private I understand how that works. However, since all

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.