Vote count:
0
Is there a way to read a file in C# which is being appended by another process.
I have tried out this code
using (var sr = new StreamReader(fs, Encoding.UTF8))
{
string line;
while ((line = sr.ReadLine()) != null)
{
yield return line;
}
}
But this only reads that part which was written at the time of opening the stream.
What I am trying to do is to synchronize two files and replicate anything written to a file to another file so I can make a mirror copy of it.
One of the way is to continuously poll the file size and if it is changed, open it and start reading from the last position however I think that there should be a better way for doing this. What I am looking is some sort of way where I don't have to close and open the file again and again.
asked 51 secs ago
Aucun commentaire:
Enregistrer un commentaire