© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
126 replies
Alex

❔ Processes and Async

How can I recreate this with Async? (BeginOutputReads and such)
// If an error happens, prints it and returns 1.
            if (proc.StandardError.Peek() != -1)
            {
                Console.Clear(); Console.ForeColor = Color.Firebrick;

                while (!proc.StandardError.EndOfStream)
                    Console.AppendText(Logging.LOGGER.Error(await proc.StandardError.ReadLineAsync()) + Environment.NewLine);

                return 1;
            }
            
            while (!proc.StandardOutput.EndOfStream)
            {
                // Read the output line by line, and wait for the "Done" line to be printed.
                await Task.Delay(100);
                
                string line = await proc.StandardOutput.ReadLineAsync();
                Logging.LOGGER.Info(line);
                if (line != null && !line.Contains("Done")) continue;
                
                Console.AppendText(Logging.LOGGER.Info("Server is DONE, killing process") + Environment.NewLine);
                break;
            }
// If an error happens, prints it and returns 1.
            if (proc.StandardError.Peek() != -1)
            {
                Console.Clear(); Console.ForeColor = Color.Firebrick;

                while (!proc.StandardError.EndOfStream)
                    Console.AppendText(Logging.LOGGER.Error(await proc.StandardError.ReadLineAsync()) + Environment.NewLine);

                return 1;
            }
            
            while (!proc.StandardOutput.EndOfStream)
            {
                // Read the output line by line, and wait for the "Done" line to be printed.
                await Task.Delay(100);
                
                string line = await proc.StandardOutput.ReadLineAsync();
                Logging.LOGGER.Info(line);
                if (line != null && !line.Contains("Done")) continue;
                
                Console.AppendText(Logging.LOGGER.Info("Server is DONE, killing process") + Environment.NewLine);
                break;
            }
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,828Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements
Next page

Similar Threads

❔ Websockets and Async
C#CC# / help
3y ago
❔ Enumerating Running Processes
C#CC# / help
3y ago
❔ Multiple Processes communication
C#CC# / help
4y ago
✅ async/await and parallelism
C#CC# / help
13mo ago