I wonder how can I wait exactly one second using a special function called WastedTime
which takes one argument MaxDelay
and inside the method it does some weird calculations causing the program to waste time with calculations. I want to waste exactly one second. After a lot of attempts, 360,000,00
seems to work. But how can I validate that the program sleep for one second?
More body performance in a loop will waste more computation time - resulting in a delay between prints. Write the full method that accepts the MaxDelay value as a parameter and place it in the main program call it that way Let the clock print a line every second. Check what is the most appropriate value for MaxDelay to run the watch accurately. Try running for a minute And compare to a real watch.
For now it seems like it actually wait one second but I wonder how can I make sure it does?
using System;
class Program
{
static void Main(string[] args)
{
const int MaxDelay = 36000000; // (360,000,00)
for (int h = 0; h < 24; h++)
for (int m = 0; m < 60; m++)
for (int s = 0; s < 60; s++)
{
WasteTime(MaxDelay);
Console.WriteLine(h + ":" + m + ":" + s);
}
}
static void WasteTime(int MaxDelay)
{
double temp = 0;
for (int delay = 1; delay <= MaxDelay; delay++)
temp = Math.Pow(Math.PI, 2);
}
}
Expected Output
0:0:0
// .. one second
0:0:1
// .. second
0:0:2
Note: Please leave the WasteTime
as is