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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:22:31+00:00 2026-05-30T13:22:31+00:00

My laptop has 2 logical processors and I stumbled upon the scenario where if

  • 0

My laptop has 2 logical processors and I stumbled upon the scenario where if I schedule 2 tasks that take longer than 1 second without designating them long-running, subsequent tasks are started after 1 second has elapsed. It is possible to change this timeout?

I know normal tasks should be short-running – much shorter than a second if possible – I’m just wondering I am seeing hard-coded TPL behavior or if I can influence this behavior in any way other than designating tasks long-running.

This Console app method should demonstrate the behavior for a machine with any number of processors:

static void Main(string[] args)
{
    var timer = new Stopwatch();
    timer.Start();

    int numberOfTasks = Environment.ProcessorCount;

    var rudeTasks = new List<Task>();
    var shortTasks = new List<Task>();

    for (int index = 0; index < numberOfTasks; index++)
    {
        int capturedIndex = index;
        rudeTasks.Add(Task.Factory.StartNew(() =>
        {
            Console.WriteLine("Starting rude task {0} at {1}ms", capturedIndex, timer.ElapsedMilliseconds);
            Thread.Sleep(5000);
        }));
    }

    for (int index = 0; index < numberOfTasks; index++)
    {
        int capturedIndex = index;
        shortTasks.Add(Task.Factory.StartNew(() =>
        {
            Console.WriteLine("Short-running task {0} running at {1}ms", capturedIndex, timer.ElapsedMilliseconds);
        }));
    }

    Task.WaitAll(shortTasks.ToArray());
    Console.WriteLine("Finished waiting for short tasks at {0}ms", timer.ElapsedMilliseconds);

    Task.WaitAll(rudeTasks.ToArray());
    Console.WriteLine("Finished waiting for rude tasks at {0}ms", timer.ElapsedMilliseconds);

    Console.ReadLine();
}

Here is the app’s output on my 2 proc laptop:

Starting rude task 0 at 2ms
Starting rude task 1 at 2ms
Short-running task 0 running at 1002ms
Short-running task 1 running at 1002ms
Finished waiting for short tasks at 1002ms
Finished waiting for rude tasks at 5004ms

Press any key to continue . . .

The lines:

Short-running task 0 running at 1002ms
Short-running task 1 running at 1002ms

indicate that there is a 1 second timeout or something of that nature allowing the shorter-running tasks to get scheduled over the ‘rude’ tasks. That’s what I’m inquiring about.

  • 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-30T13:22:33+00:00Added an answer on May 30, 2026 at 1:22 pm

    The behavior that you are seeing is not specific to the TPL, it’s specific to the TPL’s default scheduler. The scheduler is attempting to increase the number of threads so that those two that are running don’t “hog” the CPU and choke out the others. It’s also helpful in avoiding deadlock situations if the two that are running start and wait on Tasks themselves.

    If you want to change the scheduling behavior, you might want to look into implementing your own TaskScheduler.

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

Sidebar

Related Questions

I always find myself close to useless without my laptop. It has all the
Imagine this scenario: You have a desktop and a laptop. The desktop has a
My Lenovo laptop has two task bar type programs that show the network status
I have a table called Laptop that has a column named HD. How can
I want to install sql server 2008 express on my laptop that has 1
I work with a Dell XPS M1710. The laptop has lights in the lid,
I plan to build a small audio-recorder app in C#. My laptop has a
My boss is running a laptop which has a setting which is resizing font
My laptop has a number pad, but it does not have a NumLock key,
My laptop has a microphone in it. Is there any method of obtaining numbers

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.