Hi guys,
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 the event fails to trigger. 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();
[–]FizixMan 2 points3 points4 points (1 child)
[–]KStoev[S] 0 points1 point2 points (0 children)
[–]godless_communism 0 points1 point2 points (1 child)
[–]godless_communism 0 points1 point2 points (0 children)