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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T23:14:18+00:00 2026-06-07T23:14:18+00:00

I am newbie to parallel programming. I write the basic code below but it

  • 0

I am newbie to parallel programming. I write the basic code below but it doesnt run always as I excepted.

Console.WriteLine ("Start");

Task task = Task.Factory.StartNew(() => {

  for (int i = 0; i < 5; i++)
{
    Console.WriteLine (i);
}

});

Console.WriteLine ("End");

I usually could not get the result of the loop 8-9 out of 10 trials. Sometimes it prints the loop results, sometimes not. But I it always prints the Start and End. Whats happening at the behind side ? Why sometimes I could not get the result of loop from time to time ?

Thanks in advance,

  • 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-07T23:14:20+00:00Added an answer on June 7, 2026 at 11:14 pm

    Your program is terminating before the parallel loop gets a chance to print any output.

    Console.WriteLine ("Start");
    Task task = Task.Factory.StartNew(() => {
    for (int i = 0; i < 5; i++)
    {
        Console.WriteLine (i);
    }
    });
    
    Console.ReadLine();
    Console.WriteLine("End");
    

    Pause by waiting for input, and you’ll see the loop run correctly.

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

Sidebar

Related Questions

Newbie question but I can't find the answer. On first run my app is
python newbie here. I'm writing the code to control an experiment that has multiple
Newbie here programming my first app (having made several tutorial apps). I am using
Newbie C++ programmer here. I'm trying to write a command line application that takes
Newbie still learning, been trying to search and hack code together for hours now,
When I try the following code double start = omp_get_wtime(); long i; #pragma omp
newbie with windows gui programming here. Has Anyone got an idea how to resize
Newbie here...can I write one program which incorporates .NET LINQ and also various Java
I'm newbie programming for mac and i'm really surprised on Grand Central Dispatch. I
I'm a complete newbie to multi-threading in C++, and decided to start with the

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.