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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:18:25+00:00 2026-06-15T22:18:25+00:00

I have an object that returns a System.Threading.Tasks.Task : public class MyClass { public

  • 0

I have an object that returns a System.Threading.Tasks.Task:

public class MyClass 
{
    public Task GetTask(object state, CancellationToken cancellationToken)
    {
        return new Task(Execute, state, cancellationToken);
    }

    public void Execute(object context)
    {
        //do stuff
    }
}

Elsewhere I have a List<MyClass>, so I do the following to get a List<Task>:

var myTaskList = myClassList.Select(p => p.GetTask(null, cancellationToken)).ToList();

Now that I have the List<Task>, how can I start them all in parallel? Is there a more concise way to code this?

Thanks!

  • 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-15T22:18:26+00:00Added an answer on June 15, 2026 at 10:18 pm

    What do you mean by “start them in parallel”? When you run the Task, it executes on another thread, so you probably mean simply:

    foreach(var task in myTaskList)
    {
        task.Start();
    }
    

    But if you have so many of them that you want to move the starting logic to another thread, you can either call the above code in another thread/task (I’m using List<T>.ForEach for shorter code).

    Task.Factory.StartNew(() => myTaskList.ForEach(task => task.Start()));
    

    Or you can use TPL’s Parallel.ForEach. That would still block the executing thread until all the Tasks are started, but it will execute the start action on an internal threadpool, so for large numbers of items and some free CPU cores/threads, it might speed up the starting considerably.

    Parallel.ForEach(myTaskList, task => task.Start());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ASP.NET WebService that returns an object of List public class Students
I have a basic web service that returns the following object as JSON: public
In F# I have a function that returns System.Linq.Expression instances: and System.Object with member
If I have an interface such as: using System.Threading.Tasks; ... public interface IFoo {
I have a class that creates and uses a System.Threading.Timer, something like this: using
I have an object that returns a value if successful and false (or nil)
I have an object with a method that returns a filehandle, and I want
I have a LINQ query that returns some object like this... var query =
I have a Linq query that returns an object of the type IQueryable<ClassX> .
I have method that returns Drawable , and if its Bitmap object is recycled

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.