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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T10:08:36+00:00 2026-05-21T10:08:36+00:00

I have a method that contains a series of method calls in it. Some

  • 0

I have a method that contains a series of method calls in it. Some of these method calls can occur at once and some have to be done sequentially. What is the most straight forward way to implement that in Task Parallel Library. All functions are calculation heavy and take less than a second to run.
i.e.

public object MyMethod(InputClass myInput)
{
    var result = method1(myInput);
    var result1 = method2(result);
    var result2 = method3(result);
    var finalResult = method4(result1, result2);
    return finalResult;   
}

Method1 must be executed 1st, method2 + method3 can be executed in parallel, method4 must be executed last.

  • 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-21T10:08:37+00:00Added an answer on May 21, 2026 at 10:08 am

    I believe this would give the the level of parallelism you require, with method 2 and 3 being executed concurrently.

    public void MyMethod(InputClass myInput)
    {
        TaskFactory<object> t = new TaskFactory<object>();
    
        var result = method1(myInput);  // Execute Synchronously
    
        Task<object> t1 = t.StartNew(method2, result); // Create and start new concurrent task
        Task<object> t2 = t.StartNew(method3, result); // Create and start new concurrent task
    
        t1.Wait(); //Wait for completion
        t2.Wait(); //Wait for completion
    
        var finalResult = method4(t1.Result, t2.Result);  // Execute Synchronously
    }
    

    EDIT: Updating with some types, assuming all your methods return object.

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

Sidebar

Related Questions

I have a model called Details that contains a method that updates some attributes
I have a method that contains the following (Java) code: doSomeThings(); doSomeOtherThings(); doSomeThings() creates
I have a data type that contains a set and a method that expects
I have an interface that contains a single method called ListAll() using System.Collections.Generic; namespace
I have a C# string object that contains the code of a generic method,
I have a class that contains a collection. I want to provided a method
I have my main application delegate which contains a method that returns an object.
I have a class that contains two methods like these: public String getFoo(Int32 a)
I have class method that returns a list of employees that I can iterate
I have a method that can return either a single object or a collection

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.