public void Read3_StopWhileInternalRead() { var path = Path.GetTempFileName(); try { using (Stream ofs = new FileStream(path, FileMode.Open, FileAccess.Write, FileShare.Read)) using (TextWriter writer = new StreamWriter(ofs)) { writer.WriteLine("こんにちは"); writer.Flush(); using (WaitableReadFileStream ifs = new WaitableReadFileStream(path, FileMode.Open, FileAccess.Read, FileShare.Delete | FileShare.ReadWrite)) using (TailFollowStream tail = new TailFollowStream(ifs)) using (TextReader reader = new StreamReader(tail)) { var job = Task <bool> .Factory.StartNew(() => { Assert.AreEqual("こんにちは", reader.ReadLine()); Assert.AreEqual("さようなら", reader.ReadLine()); ifs.ReadWait = 1000; Assert.IsNull(reader.ReadLine()); return(true); }); writer.WriteLine("さようなら"); writer.Flush(); Thread.Sleep(500); reader.Close(); job.Wait(); Assert.True(job.Result); } } } finally { File.Delete(path); } }
public void Read3_StopWhileInternalRead() { var path = Path.GetTempFileName(); try { using (Stream ofs = new FileStream(path, FileMode.Open, FileAccess.Write, FileShare.Read)) using (TextWriter writer = new StreamWriter(ofs)) { writer.WriteLine("こんにちは"); writer.Flush(); using (WaitableReadFileStream ifs = new WaitableReadFileStream(path, FileMode.Open, FileAccess.Read, FileShare.Delete | FileShare.ReadWrite)) using (TailFollowStream tail = new TailFollowStream(ifs)) using (TextReader reader = new StreamReader(tail)) { var job = Task<bool>.Factory.StartNew(() => { Assert.AreEqual("こんにちは", reader.ReadLine()); Assert.AreEqual("さようなら", reader.ReadLine()); ifs.ReadWait = 1000; Assert.IsNull(reader.ReadLine()); return true; }); writer.WriteLine("さようなら"); writer.Flush(); Thread.Sleep(500); reader.Close(); job.Wait(); Assert.True(job.Result); } } } finally { File.Delete(path); } }