Does this code loop infinitely?
c#, timer
Solution
KISS - or are you competing for the Rube Goldberg award? ;-)
static void Main(string[] args)
{
while(true)
{
DoSomething();
if(Console.KeyAvailable)
{
break;
}
System.Threading.Thread.Sleep(60000);
}
}
Problem
I have the following code, does this run an endless loop? I am trying to schedule something every minute and the console application should run continuously until I close it. ``` class Program { static int curMin; static int lastMinute = DateTime.Now.AddMinutes(-1).Minutes; static void Main(string[] args) { // Not sure about this line if it will run continuously every minute?? System.Threading.Timer timer = new System.Threading.Timer(new TimerCallback(TimCallBack), null, 1000, 60000); Console.Read(); timer.Dispose(); } private static void TimCallBack(object o) { curMin = DateTime.Now.Minute; if (lastMinute < curMin) { // Do my work every minute lastMinute = curMin; } } } ```