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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:13:30+00:00 2026-05-27T00:13:30+00:00

Following to this post , I want parallelize this method : public IEnumerable<string> GetAllLogs(IEnumerable<IComputer>

  • 0

Following to this post, I want parallelize this method :

    public IEnumerable<string> GetAllLogs(IEnumerable<IComputer> computers)
    {
        foreach (var cpt in computers)
        {
            foreach (var log in cpt.GetLogs())
            {
                yield return log;
            }
        }
    }

I want the method “yield returns” a log when one of the method GetLogs is finished. If I have 4 computers which returns :

  • Computer 01 : “a”, “b”, “c”, “d”, “e”
  • Computer 02 : “1”, “2”, “3”, “4”, “5”
  • Computer 03 : “alpha”, “beta”, “gamma”, “delta”, “epsilon”
  • Computer 04 : “I”, “II”, “III”, “IV”, “V”

With the “sequential method”, the output is :

a
b
c
d
e
1
2
3
4
5
alpha
beta
gamma
delta
epsilon
I
II
III
IV
V

And the methods runs in 20 seconds. there is a Thread.Sleep(1000) in the GetLogs method.

I want the output looks like this :

III
a
4
gamma
b
c
IV
5
d
II
beta
e
1
2
delta
alpha
3
epsilon
I

and runs in few seconds.

I want to the methods returns an IEnumerable

  • 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-27T00:13:31+00:00Added an answer on May 27, 2026 at 12:13 am

    This is what you need:

    public IEnumerable<string> GetAllLogsParallel(IEnumerable<IComputer> computers)
    {
        return computers
            .AsParallel()
            .SelectMany(cpt => cpt.GetLogs());
    }
    

    If you want to start processing of 4 computer-s at the same time you can adjust the degree of parallelism like this:

    public IEnumerable<string> GetAllLogsParallel(IEnumerable<IComputer> computers)
    {
        return computers
            .AsParallel()
            .WithDegreeOfParallelism(4)
            .SelectMany(cpt => cpt.GetLogs());
    }
    

    Following is a simplified explanation just for understanding.
    To learn more about that just visit PLINQ (Parallel LINQ) at MSDN.

    Well, .AsParallel() – splits the computers enumerable into 4 parts and starts 4 threads at the same time. Each thread executes cpt.GetLogs() for each computer. The result is IEnumerable<IEnumerable<string>> – enumerable of enumerables. SelectMany() is used to flatten this list by concatenating inner enumerables and eliminating outer ones. Results are merged back automatically into the main thread in the order of their arrival.

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

Sidebar

Related Questions

Regarding this post and this other one . Suppose I have the following: public
What could be the understanding of the following? I have gone through this post
I'm trying to implement routing such as the following: posts/535434/This-is-a-post-title posts/tagged/tags+here // Matches {controller}/{action}/{id}
Following on from this post - what are the disadvantages when using the -=
I am following this great post to configure my rails production server on ubuntu
This post is a follow-up of this answered question: Best method for storing a
Im trying to get the last string from a URL for example... http://www.mywebsite/blog/this-post I
I checked this post already. But it doesn't answer my question. I want to
i want to select the following strings from this html using just lxml and
I want to chmod recursively in my build.xml and borrowed the following from this

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.