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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:12:47+00:00 2026-05-27T08:12:47+00:00

I want to process something using parallel loop like this : public void FillLogs(IEnumerable<IComputer>

  • 0

I want to process something using parallel loop like this :

public void FillLogs(IEnumerable<IComputer> computers)
{
    Parallel.ForEach(computers, cpt=>
    {
        cpt.Logs = cpt.GetRawLogs().ToList();
    });

}

Ok, it works fine. But How to do if I want the FillLogs method return an IEnumerable ?

public IEnumerable<IComputer> FillLogs(IEnumerable<IComputer> computers)
{
    Parallel.ForEach(computers, cpt=>
    {
        cpt.Logs = cpt.GetRawLogs().ToList();
        yield return cpt // KO, don't work
    });

}

EDIT

It seems not to be possible… but I use something like this :

public IEnumerable<IComputer> FillLogs(IEnumerable<IComputer> computers)
{
    return computers.AsParallel().Select(cpt => cpt);
}

But where I put the cpt.Logs = cpt.GetRawLogs().ToList(); instruction

  • 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-27T08:12:47+00:00Added an answer on May 27, 2026 at 8:12 am

    Short version – no, that isn’t possible via an iterator block; the longer version probably involves synchronized queue/dequeue between the caller’s iterator thread (doing the dequeue) and the parallel workers (doing the enqueue); but as a side note – logs are usually IO-bound, and parallelising things that are IO-bound often doesn’t work very well.

    If the caller is going to take some time to consume each, then there may be some merit to an approach that only processes one log at a time, but can do that while the caller is consuming the previous log; i.e. it begins a Task for the next item before the yield, and waits for completion after the yield… but that is again, pretty complex. As a simplified example:

    static void Main()
    {
        foreach(string s in Get())
        {
            Console.WriteLine(s);
        }
    }
    
    static IEnumerable<string> Get() {
        var source = new[] {1, 2, 3, 4, 5};
        Task<string> outstandingItem = null;
        Func<object, string> transform = x => ProcessItem((int) x);
        foreach(var item in source)
        {
            var tmp = outstandingItem;
    
            // note: passed in as "state", not captured, so not a foreach/capture bug
            outstandingItem = new Task<string>(transform, item);
            outstandingItem.Start();
    
            if (tmp != null) yield return tmp.Result;
        }
        if (outstandingItem != null) yield return outstandingItem.Result;
    }
    static string ProcessItem(int i)
    {
        return i.ToString();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a for loop I want to parallelize with something like PLINQ's Parallel.ForEach().
I want to process every element of a for-loop. Taking this code, why is
I want to process a medium to large number of text snippets using a
I have some data generated in MATLAB that I want to process using Perl.
Using XSLT 1.0, I want to process four node sets, in order, A, B,
I want to get the community's perspective on this. If I have a process
I have a directory logfiles. I want to process each file inside this directory
I want to run something like cat file.tar | base64 | myprogram -c |
I want to process a large number of independant lines in parallel. In the
I want to process each source code file after it has been preprocessed: myprocess

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.