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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:02:13+00:00 2026-06-13T18:02:13+00:00

Please consider the following code public static async Task<int> Answer() { await Task.Delay(1000); return

  • 0

Please consider the following code

    public static async Task<int> Answer()
    {
        await Task.Delay(1000);
        return 42;
    }

    static void Main(string[] args)
    {
        for (int j = 0; j < 20; j++)
        {
            Console.WriteLine(j +" " + Thread.CurrentThread.IsThreadPoolThread);
            if (j == 1)
            {
                new Task( async ()=>
                    {
                        int answer = await Answer();
                        Console.WriteLine(answer + " " + Thread.CurrentThread.IsThreadPoolThread);
                    }).Start();
            }

            Thread.Sleep(200);
        }

        return;

Can you guess what the CurrentThread.IsThreadPoolThread when printing answer is?

It appears that Task.Delay(..) is doing it, for if I remove await, then the answer is False. However, I can not seem to find that Delay actually puts stuff on the thread pool in the documentation.

This brings me to the more general question. What in Task does actually start up a thread pool thread besides Run(..)?

Edit:
Replacing new Task(...) with Ask()

    public static async void Ask()
    {
        int answer = await Answer();
        Console.WriteLine(answer + " " + Thread.CurrentThread.IsThreadPoolThread);
    }

yields the same result

  • 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-13T18:02:15+00:00Added an answer on June 13, 2026 at 6:02 pm

    As I describe in my async / await intro post, by default await will capture the current “context” and use that to execute the continuation (the code after the await). This “context” is SynchronizationContext.Current unless it is null, in which case it is TaskScheduler.Current.

    I also describe using async on Console apps on my blog. Console apps do not provide a SynchronizationContext, so the “context” falls back to TaskScheduler.Current. Since the currently-executing Task is running on the thread pool, TaskScheduler.Current is the same as TaskScheduler.Default, which is the thread pool task scheduler.

    This is why your code is resuming on a thread pool thread. It’s the correct behavior.

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

Sidebar

Related Questions

Please consider the following code: #include <stdio.h> int main() { static int counter=5; printf
Please consider the following code: public class Person ( public string FirstName {get; set;}
Please consider the following java source: package com.stackoverflow; public class CondSpeed { private static
Please consider the following simple use case: public class Foo { public virtual int
Please consider the following code: class Abase{}; class A1:public Abase{}; class A2:public A1{}; //etc
Please pardon me for a n00bish question. Please consider the following code: public class
Please consider the following code: <!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd> <html
Please consider the following code: type TFoo1 = class public procedure DoSomething1; end; TFoo2
Consider the following code: #include <iostream> class Bar { public: void foo(bool b =
Please consider the following code: typedef struct { int type; } object_t; typedef struct

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.