我有一个控制台应用程序启动一个过程(大约需要2-3个小时才能完成)
有没有办法可以显示一条消息“进程正在运行...”每隔几分钟,下面是代码:
using (process)
{
var output = new StringBuilder();
var error = new StringBuilder();
using (var outputWaitHandle = new AutoResetEvent(false))
using (var errorWaitHandle = new AutoResetEvent(false))
{
process.OutputDataReceived += (sender, e) =>
{
if (e.Data == null)
{
outputWaitHandle.Set();
}
else
{
output.AppendLine(e.Data);
}
};
process.ErrorDataReceived += (sender, e) =>
{
if (e.Data == null)
{
errorWaitHandle.Set();
}
else
{
error.AppendLine(e.Data);
}
};
process.Start();
Console.WriteLine("Process is running..."); // THIS ONLY DISPLAYS ONCE
process.BeginOutputReadLine();
process.BeginErrorReadLine();
process.WaitForExit();
Console.WriteLine("Process has shutdown...")
}