I am currently working on a school project that requires data to be generated, processed and stored every 2 seconds. For that, I am using while(true) loop. The problem I have is allowing user to break that loop and request generated data. Generating/storing has to be a continuous process that happens in the background, so I can't ask user for input at the beginning of each iteration. I hope someone could help me out. This would be a simple example:
int i = 0;
List<int> list = new List<int>();
//Console.WriteLine("Generating will continue until any key is pressed... ");
while (true)
{
i++;
li.Add(i);
Thread.Sleep(2000);
}
foreach (int i in list)
{
Console.Writeline(i);
}