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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:57:22+00:00 2026-06-17T09:57:22+00:00

There’s something unclear to me about the inner workings of TaskCompletionSource<> . When creating

  • 0

There’s something unclear to me about the inner workings of TaskCompletionSource<>.

When creating a simple Task<> using the Factory, I expect this task to be enqueued in a thread pool, unless I specify TaskCreationOptions.LongRunning, where it will run in a new thread instead.

My understanding of TaskCompletionSource, is that I am responsible of triggering when a task ends, or fails, and I have full control on how to manage threads.
However, the ctor of TaskCompletionSource allows me to specify a TaskCreationOptions, and this confuse me, since I was expecting the Scheduler not being able to handle the task itself.

What is the purpose of TaskCreationOptions in the context of a TaskCompletionSource<>?

Here is an example of use:

public Task<WebResponse> Download(string url)
{
    TaskCompletionSource<WebResponse> tcs = 
    new TaskCompletionSource<WebResponse>(TaskCreationOptions.LongRunning);

    var client = (HttpWebRequest)HttpWebRequest.Create(url);
    var async = client.BeginGetResponse(o =>
      {
          try
          {
              WebResponse resp = client.EndGetResponse(o);
              tcs.SetResult(resp);
          }
          catch (Exception ex)
          {
              tcs.SetException(ex);
          }
      }, null);


    return tcs.Task;
}
  • 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-17T09:57:24+00:00Added an answer on June 17, 2026 at 9:57 am

    The answer is that a TaskCreationOption is useful for its AttachToParent option only, as TaskCompletionSource can be the child of any other task.
    Options related to thread management or execution ordering aren’t relevant in the context of a TaskCompletionSource. The following code actually throws an exception:

    new TaskCompletionSource<WebResponse>(TaskCreationOptions.LongRunning);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There are nice SO question and answers about this issue, but these options didn't
There is about 2000 lines of this, so manually would probably take more work
There is a column that exists in 2 tables. In table 1, this column
There was a similar question posted asking in general about alternatives to Qt. Well,
There was a smbmrx sample code using RDBSS in WDK Vista. But since WDK
There's no Sort() function for IList . Can someoene help me with this? I
There are are 150 000 records in my comments table and about 1000 new
There was a thread on this in comp.lang.javascript recently where victory was announced but
There's obviously something I'm missing here - I've been through the developer.android reference and
I know there's a lot of other questions out there that deal with this

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.