So i have big Text
file that i want to read and take specific block (about 30 lines).
This block exist many times in my text file and i want to take the last.
So this is what i have try:
while (true)
{
Thread.Sleep(30000);
string text = File.ReadAllText(@"c:\file.txt");
string table = string.Join("", text.Substring(text.LastIndexOf("My Statistics:"))
.Split(new[] { '\n' })
.Take(24)
.Select(i => i.ToString())
.ToArray());
File.WriteAllText(@"last.txt", table);
}
This Text
file changed every 20 second so i am doing this with while loop and i need to write the last block on new Text
file.
The problem here that after the first time (that works fine) i got an error: OutOfMemoryException
EDIT
I try another approach and read line by line but the result was the same.