I want to process only X number of files at a time for below infinite loop. Below codes give me all files at a time, how to get only X number of files?
while (true)
{
var files = new DirectoryInfo(@"path")
.GetFiles()
.OrderBy(p => p.LastWriteTimeUtc)
.ToList();
foreach (var f in files)
{
//do some processing
Console.WriteLine(f.Name);
f.Delete();
}
Thread.Sleep(5000);
}