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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:07:28+00:00 2026-05-27T22:07:28+00:00

I’m reading a book called Pro .NET 4 Parallel Programming in C# by Adam

  • 0

I’m reading a book called Pro .NET 4 Parallel Programming in C# by Adam Freeman. In Chapter 2 page 13 it talks about using Task<int> to return a result by using task1.Result to wait for it to finish. I don’t understand why task2 has to wait for task1 to finish. They are on different threads.

It’s something like below:

Task<int> task1 = new Task<int>(() => { ... ; return sum });
task1.Start();
Console.WriteLine("Result 1: {0}", task1.Result);

Task<int> task2 = new Task<int>(() => { ... ; return sum });
task2.Start();
Console.WriteLine("Result 2: {0}", task2.Result);

If I move to following line to the bottom it seems like task1 still executes first no matter how many times I tried.

Console.WriteLine("Result 1: {0}", task1.Result);

Why is this happening?

  • 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-27T22:07:28+00:00Added an answer on May 27, 2026 at 10:07 pm

    The task that actually finishes first — that is, hits its return statement first — is, formally, unpredictable. They can finish their work before you accept their Results.

    If the work your sample tasks do is not very large, it stands to reason that task1 will finish first even if you don’t accept its Result (or in Java threading lingo, join it) first. That’s because you Started it first.

    Presumably you somehow know that task1 finished first. Is there a Console.WriteLine buried in the code for your tasks? If so, keep in mind that the Console subsystem serializes operations, so the first of your tasks to use it will do so completely before the second one can start. Think of it this way: your two tasks race to Console, and the winner takes all.

    task1 has an unfair advantage in this race, because it’s off and running before your main thread even starts constructing task2 with your second new.

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

Sidebar

Related Questions

I am reading a book about Javascript and jQuery and using one of the
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
We are using XSLT to translate a RIXML file to XML. Our RIXML contains

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.