I'm new to async/await
and I have tried to create a responsive clock as a demo. the clock worked fine, but when I tried to get it into asynchronous function and awaited the delay it stopped working, displaying only the time in which it ran. here is the code:
public static async void clock ()
{
while (true)
{
Console.WriteLine(DateTime.Now.ToString());
await Task.Delay(1000);
Console.Clear();
}
}
and the main is just:
clock();
edit:
its seems like the App doesn't run thro the stage of the await Task.Delay(1000);
which leads me to believe that there is an infinite delay, probably because of the await
. but as far as I know, logically it should not happen, I also have seen some examples of using await
on delay, so it must be possible to do.