[英]How can I read lines from a live file?
I've got 2 apps, one writes lines to a file, the other reads as the file is written.我有 2 个应用程序,一个将行写入文件,另一个在写入文件时读取。 The issue comes from regarding the file as a queue and not as a stream.问题来自将文件视为队列而不是 stream。 the writing is per line.写作是每行。 reading with StreamReader::ReadLine.使用 StreamReader::ReadLine 阅读。 The issue is that i'm getting only part of the line, so parsing fails.问题是我只得到了部分行,所以解析失败。 What is the best way to solve this issue?解决此问题的最佳方法是什么?
.NET Framework offers a PipeStream and derived classes for inter-process communication on a local machine as a client-server using a stream in memory, not a file as in Unix as can be done using semaphores and queued pipes. .NET Framework offers a PipeStream and derived classes for inter-process communication on a local machine as a client-server using a stream in memory, not a file as in Unix as can be done using semaphores and queued pipes.
If you need one process populating a file, you can do that it send new data after written in the file to the other process using such stream pipe.如果您需要一个进程填充文件,您可以使用 stream pipe 将文件写入文件后将新数据发送到另一个进程。
For example, in the server process:例如,在服务器进程中:
void ProcessNewData(string /* or any type needed */ content)
{
WriteNewDataToFile(content);
SendNewDataToClient(content);
}
Here is an article that explain things in addition to the Microsoft documentation:除了 Microsoft 文档之外,还有一篇文章解释了一些事情:
Full Duplex Asynchronous Read/Write with Named Pipes (CodeProject) 使用命名管道的全双工异步读/写 (CodeProject)
You can also use any inter-process technology you want: Remoting, WCF...您还可以使用任何您想要的进程间技术:Remoting、WCF...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.