C#如何实现读取一个实时更新的文本文件
最近遇到比较棘手的问题,有一个文本文件是实时更新的,有另外一个程序实时地往该文本文件里写入内容。现在需要的是实现:从这个实时更新的文件中,读取里面的内容,并在控制台中显示。
2011-09-21 20:54

2011-09-22 08:11
程序代码:static void Main(string[] args)
{
try
{
Console.Title = "监视台";
Process P = new Process();
P.StartInfo.FileName = "程序路径";
P.StartInfo.UseShellExecute = false;
P.StartInfo.RedirectStandardOutput = true;
Console.WriteLine(">>[" + DateTime.Now.ToString() + "]启动程序\r\n");
P.Start();
string strmsg = "";
while (!P.StandardOutput.EndOfStream)
{
strmsg = P.StandardOutput.ReadLine();
if (strmsg != "")
{
Console.WriteLine(">>[" + DateTime.Now.ToString() + "]" + strmsg + "\r\n");
}
}
Console.WriteLine("按任意键退出.");
Console.ReadKey(true);
}
catch
{
}
}
2011-09-22 11:38
2011-09-22 23:18
2011-09-23 09:09

2011-09-23 09:25

2011-09-23 09:58