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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:40:06+00:00 2026-05-24T01:40:06+00:00

The program I made throws off threads which start executables through processes. Each thread

  • 0

The program I made throws off threads which start executables through processes. Each thread runs the method below which starts the process and redirects the processes’ output into a string (info.additional which is per process).

I’ve learned through a lot of trial and error that I have to redirect output a certain way (using events for output received) or else the streams deadlock.

Now, I’m running on a dual core machine and if I have two threads running and starting processes, the program runs great and captures the output of these processes perfectly. But when I move to more than two threads (more threads than I have cores) the output sometimes doesn’t get captured for these. Why is this? And does anyone know how to fix this?
Thank you, Joe

    public void ThreadProc()
    {
        info.watch.Start();
        proc = InstantiateProcess();
        proc.Start();
        proc.BeginOutputReadLine();
    }


    private void procOutputDataReceived(object sendingProcess, DataReceivedEventArgs e)
    {
        if (e.Data != null)
        {
            //Console.WriteLine(System.Threading.Thread.CurrentThread.ManagedThreadId);
            this.info.additional += e.Data.ToString();
        }
    }
  • 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-24T01:40:07+00:00Added an answer on May 24, 2026 at 1:40 am

    Not sure if this could be causing the problem, but based on the code here your ThreadProc is exiting before the Process object is done. According to the OutputDataReceived docs, you should be calling WaitForExit() “The application that is processing the asynchronous output should call the WaitForExit() method to ensure that the output buffer has been flushed.” Based on that line I would assume you could lose some data if you are not doing that.

    On an unrelated note, Process objects implement IDisposable so I would recommend changing your ThreadProc method like this (note I don’t see a declaration of proc here, but as you say you launch multiple processes I am assuming that proc is not a member variable and the declaration was just left out in the sample):

    public void ThreadProc()
    {
        info.watch.Start();
        using (var proc = InstantiateProcess())
        {
            proc.Start();
            proc.BeginOutputReadLine();
            proc.WaitForExit();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've made a class that controls the speed at which my program runs, kind
I made a program. I also made my own file type, which the program
I made a program that opens an application, sleeps the thread for 500ms then
I am trying to start a program I made in this directory: C:\example\example.exe -someargument
Made a program retrieving .txt files from a folder. Each .txt files contains 1
I made a program which can generate primes. I want the program to write
I made a program in which I wanted to manually update the Data Grid
I'm trying to automate a program I made with a test suite via a
I made small program to divide large pictures and take part of them. When
I have made a program in c and wanted to see, how much memory

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.