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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:52:04+00:00 2026-06-04T11:52:04+00:00

I have a very simple C# project that has a UI process and a

  • 0

I have a very simple C# project that has a UI process and a worker process. The worker code needs to be a process (rather than a thread) because it can be run by either the UI or by the Windows Task Scheduler.

In the UI code, I set the ProcessStartInfo.RedirectStandardOutput to true and I register the event handlers. Then, I start the process (with Process.Start() and call Process.BeginOutputReadline(). Yet, the method that I have designated as the OutputDataReceived event handler never fires. When I run the worker process without redirecting it’s standard output, I see the expected output on the console. When I turn on output redirection, I don’t see anything on the console (as expected), but the event handlers don’t fire either. Is there something else that I need to to read asynchronously from another process’ standard output stream?

EDIT: I’ve managed to replicate the problem with two simple console processes.

First the parent:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Diagnostics;

namespace OutputRedirectionEventHandlerTest
{
    class ParentProgram
    {
        static void Main(string[] args)
        {
            ProcessStartInfo processInfo = new ProcessStartInfo()
            {
                FileName = "OutputRedirectionWorker.exe",
                RedirectStandardOutput = true,
                UseShellExecute = false
            };
            Process subProcess = new Process()
            {
                StartInfo = processInfo
            };
            subProcess.OutputDataReceived += 
                new DataReceivedEventHandler(OutputHandler);
            subProcess.Start();
            subProcess.BeginOutputReadLine();


        }

        static void OutputHandler(object SendingProcess, 
            DataReceivedEventArgs args)
        {
            Console.Out.WriteLine("Received from subprocess: " + args.Data);
        }

    }
}

And then, the child:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Threading;

namespace OutputRedirectionWorker
{
    class ChildProgram
    {
        static void Main(string[] args)
        {
            Console.Out.WriteLine("Output1");
            Console.Out.WriteLine("Output2");
            Console.Out.WriteLine("Output3");
            Thread.Sleep(10000);
        }

    }
}

No output ever gets printed by the parent.

  • 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-04T11:52:05+00:00Added an answer on June 4, 2026 at 11:52 am

    You need to understand that the call to BeginOutputReadLine returns immediately. It kicks off an asynchronous read of standard output.

    The problem in the example that you provided is that the Parent program exits immediately after calling BeginOutputReadLine. It never has a chance to read the output- it is exiting before the ChildProgram even starts. You need to keep the parent running using a loop of some kind in order for it to read the standard output.

    Try something like this:

    static void Main(string[] args)
        {
            ProcessStartInfo processInfo = new ProcessStartInfo()
            {
                FileName = "OutputRedirectionWorker.exe",
                RedirectStandardOutput = true,
                UseShellExecute = false
            };
            Process subProcess = new Process()
            {
                StartInfo = processInfo
            };
            subProcess.OutputDataReceived += 
                new DataReceivedEventHandler(OutputHandler);
            subProcess.Start();
            subProcess.BeginOutputReadLine();
    
            while (Console.ReadLine().ToLower() != "quit") {
                // looping here waiting for the user to type quit
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very simple Setup project that copies three dlls into the GAC.
I have a very simple Mac Cocoa app that just has a Web View
I have a very simple class that has a single property and which inherits
I have a very simple view that has a DropDownListFor and a Button inside
I have apsx page that has the following simple code: <%@ Page Title= Language=C#
I have a really simple webapp project with maven and jetty that has been
I have created a very simple GUI project in Qt as follows: main: #include
Hope you are fine. I have to make a Web Project (very simple) I
I have a very simple webforms app that will allow field techs to order
I have a very simple table with two columns, but has 4.5M rows. CREATE

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.