変更を監視し、独自の変更を追加したいデータを含むファイルがあります。「Tail -f foo.txt」のように考えてください。
このスレッドに基づいて、ファイルストリームを作成し、それをライターとリーダーの両方に渡す必要があるようです。ただし、リーダーが元のファイルの最後に到達すると、自分で書いた更新が表示されません。
奇妙な状況のように思えることはわかっています...それができるかどうかを確認するための実験です.
私が試した例は次のとおりです。
foo.txt:
a
b
c
d
e
f
string test = "foo.txt";
System.IO.FileStream fs = new System.IO.FileStream(test, System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.ReadWrite);
var sw = new System.IO.StreamWriter(fs);
var sr = new System.IO.StreamReader(fs);
var res = sr.ReadLine();
res = sr.ReadLine();
sw.WriteLine("g");
sw.Flush();
res = sr.ReadLine();
res = sr.ReadLine();
sw.WriteLine("h");
sw.Flush();
sw.WriteLine("i");
sw.Flush();
sw.WriteLine("j");
sw.Flush();
sw.WriteLine("k");
sw.Flush();
res = sr.ReadLine();
res = sr.ReadLine();
res = sr.ReadLine();
res = sr.ReadLine();
res = sr.ReadLine();
res = sr.ReadLine();
"f" を過ぎると、リーダーは null を返します。