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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:13:59+00:00 2026-05-13T09:13:59+00:00

I’ve recently started working on a new application which will utilize task parallelism. I

  • 0

I’ve recently started working on a new application which will utilize task parallelism. I have just begun writing a tasking framework, but have recently seen a number of posts on SO regarding the new System.Threading.Tasks namespace which may be useful to me (and I would rather use an existing framework than roll my own).

However looking over MSDN I haven’t seen how / if, I can implement the functionality which I’m looking for:

  • Dependency on other tasks completing.
  • Able to wait on an unknown number of tasks preforming the same action (maybe wrapped in the same task object which is invoked multiple times)
  • Set maximum concurrent instances of a task since they use a shared resource there is no point running more than one at once
  • Hint at priority, or scheduler places tasks with lower maximum concurrent instances at a higher priority (so as to keep said resource in use as much as possible)
  • Edit ability to vary the priority of tasks which are preforming the same action (pretty poor example but, PredictWeather (Tommorrow) will have a higher priority than PredictWeather (NextWeek))

Can someone point me towards an example / tell me how I can achieve this? Cheers.

C# Use Case: (typed in SO so please for give any syntax errors / typos)

**note Do() / DoAfter() shouldn’t block the calling thread*

class Application ()
{

    Task LeafTask = new Task (LeafWork) {PriorityHint = High, MaxConcurrent = 1};
    var Tree = new TaskTree (LeafTask); 

    Task TraverseTask = new Task (Tree.Traverse); 
    Task WorkTask = new Task (MoreWork); 
    Task RunTask = new Task (Run);

    Object SharedLeafWorkObject = new Object ();

    void Entry ()
    {
        RunTask.Do ();
        RunTask.Join (); // Use this thread for task processing until all invocations of RunTask are complete
    }

    void Run(){                           
        TraverseTask.Do ();

        // Wait for TraverseTask to make sure all leaf tasks are invoked before waiting on them 
        WorkTask.DoAfter (new [] {TraverseTask, LeafTask});

        if (running){
            RunTask.DoAfter (WorkTask);   // Keep at least one RunTask alive to prevent Join from 'unblocking'
        }
        else    
        {
            TraverseTask.Join();
            WorkTask.Join ();
        }
    } 

    void LeafWork (Object leaf){
        lock (SharedLeafWorkObject)  // Fake a shared resource
        {
            Thread.Sleep (200); // 'work'
        } 
    }

    void MoreWork ()
    {
        Thread.Sleep (2000); // this one takes a while
    }
}


class TaskTreeNode<TItem>
{
    Task LeafTask; // = Application::LeafTask
    TItem Item;

    void Traverse ()
    {
        if (isLeaf)
        { 
            // LeafTask set in C-Tor or elsewhere
            LeafTask.Do(this.Item);

            //Edit
            //LeafTask.Do(this.Item, this.Depth); // Deeper items get higher priority
            return;
        }
        foreach (var child in this.children)
        {
            child.Traverse (); 
        }
    }
}
  • 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-13T09:14:00+00:00Added an answer on May 13, 2026 at 9:14 am

    There are numerous examples here:

    http://code.msdn.microsoft.com/ParExtSamples

    There’s a great white paper which covers a lot of the details you mention above here:

    “Patterns for Parallel Programming: Understanding and Applying Parallel Patterns with the .NET Framework 4”

    http://www.microsoft.com/downloads/details.aspx?FamilyID=86b3d32b-ad26-4bb8-a3ae-c1637026c3ee&displaylang=en

    Off the top of my head I think you can do all the things you list in your question.

    • Dependencies etc: Task.WaitAll(Task[] tasks)
    • Scheduler: The library supports numerous options for limiting number of threads in use and supports providing your own scheduler. I would avoid altering the priority of threads if at all possible. This is likely to have negative impact on the scheduler, unless you provide your own.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 432k
  • Answers 432k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Assuming you are using the default routes: public static void… May 15, 2026 at 2:44 pm
  • Editorial Team
    Editorial Team added an answer I decided to use CSS3 transformation on a copied HTML… May 15, 2026 at 2:44 pm
  • Editorial Team
    Editorial Team added an answer <style> #appear_div { display: none; } </style> <script type="text/javascript"> function… May 15, 2026 at 2:44 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.