I've been trying to read in real time a text file and display its last line in the console. The issue is that when the grows in size 300kb+ my code can't process it or just the event is not triggering. I did read pretty much all of the posts on google but can't really think of how to achieve this properly. Bear in mind that i'am super new to programming.
I'd be grateful if you can share any ideas on how to achieve this. Here is my sample code:
var wh = new AutoResetEvent(false);
var fsw = new FileSystemWatcher(".");
fsw.Filter = pathToFile;
fsw.EnableRaisingEvents = true;
fsw.Changed += (s, e) => wh.Set();
var fs = new FileStream("c:/test.txt", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
using (var sr = new StreamReader(fs))
{
var s = "";
while (true)
{
s = sr.ReadLine();
if (s != null && s.Contains("CActor::ClKill"))
{
await b.Channel.SendMessage(s);
Console.WriteLine("Transmitting: " + s);
}
else
{
Console.WriteLine("Sleeping...");
wh.WaitOne(1000);
}
}
}
wh.Close();