When checking for ==
you actually compare ticks: if
DateTime.Now == 2018-10-18 13:19:50.0000000
and thus there's only a tiny probability to go off Beep
:
...
DateTime.Now == 2018-10-18 13:19:49.9999852
DateTime.Now == 2018-10-18 13:19:49.9999989 // Transition: no beep here
DateTime.Now == 2018-10-18 13:19:50.0000007 // infinte loop from now on
...
Try different test (quick patch; Timer
is a better solution):
var xx = new DateTime(2018,10,8,13,19,50);
while (true)
{
// If DateTime.Now exceeds xx
if (DateTime.Now >= xx) {
// bee..eep
Console.Beep();
// and break the loop
break;
}
}