Reading file content changes in .NET

后端 未结 2 1849
难免孤独
难免孤独 2020-12-14 23:00

In Linux, a lot of IPC is done by appending to a file in 1 process and reading the new content from another process.

I want to do the above in Windows/.NET (Too mess

2条回答
  •  情深已故
    2020-12-14 23:34

        using (FileStream fs = new FileStream
           (fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
        {
            using (StreamReader sr = new StreamReader(fs))
            {
                while (someCondition)
                {
                    while (!sr.EndOfStream)
                        ProcessLinr(sr.ReadLine());
                    while (sr.EndOfStream)
                        Thread.Sleep(100);
                    ProcessLinr(sr.ReadLine());            
                }
            }
        }
    

    this will help you read only appended lines

提交回复
热议问题