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

  • Home
  • SEARCH
  • 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 7833017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T12:31:59+00:00 2026-06-02T12:31:59+00:00

I am currently working on a c# project which is using the System.Diagnostic.Process method

  • 0

I am currently working on a c# project which is using the System.Diagnostic.Process method to start up a couple of scripts within a config file.

I have a foreach loop which loops through each script that it needs to start by creating a new thread, setting up the process info and starting the process and redirect the output from that script into the c# program. I am then using the Process.OutputDataReceived event to trigger when the program receives output.

Is there a way in the OutputDataReceived event handler to determine the name of the thread that triggered the event.

The code below creates the threads and starts the thread up.

    public void prepareProductStart()
    {
        foreach ( ConfigManagement.ProductSettings product in configManagement.productSettings )
        {
            worker = new Thread(() => startProducts(product.startScript));
            worker.IsBackground = false;
            worker.Name = product.productName;
            worker.Start();
        }

When the thread has started it calls this method which will trigger the output event

    private void startProducts(string startScript)
    {
        //Thread productThread = new Thread();
        Process startProductProcess = new Process();
        startProductProcess.StartInfo.FileName = startScript;

        startProductProcess.StartInfo.UseShellExecute = false;
        startProductProcess.StartInfo.RedirectStandardOutput = true;
        StringBuilder processOutput = new StringBuilder("");
        startProductProcess.OutputDataReceived += new DataReceivedEventHandler(startProductProcess_OutputDataReceived);
        startProductProcess.Start();
        startProductProcess.BeginOutputReadLine();
    }

The output event looks like below and this event needs to determine the name of the thread so it know what to do with the output.

    private void startProductProcess_OutputDataReceived(object sender, DataReceivedEventArgs e)
    {
        //Find thread name and perform event based on thread name
    }

Thanks for any help you can provide.

  • 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-02T12:32:02+00:00Added an answer on June 2, 2026 at 12:32 pm

    Since IO callbacks are called on Threads that belong to the CLR ThreadPool and not yours, they don’t have a name. So you want to associate your thread name to your process, in fact.

    Far from elegant, but well, I guess it works:

    Add a Dictionnary<Process, string> _processTags; in your class’ attributes

    Then change startProducts to:

    private void startProducts(string startScript)
    {
        //Thread productThread = new Thread();
        Process startProductProcess = new Process();
    
        // Save tag
        _processTags.Add(startProductProcess, Thread.CurrentThread.Name);
    
        startProductProcess.StartInfo.FileName = startScript;
        startProductProcess.StartInfo.UseShellExecute = false;
        startProductProcess.StartInfo.RedirectStandardOutput = true;
        StringBuilder processOutput = new StringBuilder("");
        startProductProcess.OutputDataReceived += new DataReceivedEventHandler(startProductProcess_OutputDataReceived);
        startProductProcess.Start();
        startProductProcess.BeginOutputReadLine();
    }
    

    And startProductProcess_OutputDataReceived :

    private void startProductProcess_OutputDataReceived(object sender, DataReceivedEventArgs e)
    {
        string threadName = _processTags[sender as Process];
        // stuff...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently working on a project which will support multiple file writing specifications (imagine
I am currently working on a project which is using Apache HttpClient 4.1.2 and
I am currently working on a project which requires migration of content from different
I'm currently working on my project which consists of front and back-end written in
I am currently working on a project which creates a dictionary with an int
I'm currently working on a project in which access to an API is restricted
Our team is currently working on a large project which makes heavy use of
I'm currently working on a Haskell project which automatically tests some functions based on
Currently we are working on a project in which we need to come up
Currently I am working with the project in which I need to parse complex

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.