Мой код примерно выглядит так :
Код: Выделить всё
while (true)
{
var path = LocateFile(); // scans the expected location for new files
using StreamReader reader = new(new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
StringBuilder line = new();
DateTime? noCharsFoundSince = DateTime.UtcNow;
while (true)
{
var readResult = reader.Read();
if (readResult > 0)
{
noCharsFoundSince = null;
var @char = (char)readResult;
if (@char == '\n')
{
ProcessLine(line.ToString());
line.Clear();
}
else
{
line.Append(@char);
}
}
else
{
if (noCharsFoundSince is null) { noCharsFoundSince = DateTime.UtcNow; }
else if (DateTime.UtcNow - noCharsFoundSince.Value > MaxIdleTime) { break; }
Thread.Sleep(1000);
}
}
}
Я запускаю .NET 8 в Linux.
Подробнее здесь: https://stackoverflow.com/questions/789 ... king-in-ne
Мобильная версия