C#C
C#3y ago
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;
            }
Was this page helpful?