There are a couple of things wrong with your code.
- Setting the text of
label2
should be simplified to:
label2.Text = DateTime.Now.ToString("hh:mm:ss tt");
- As others have already pointed out, move the
if
test to the timer tick handler, as in:
if (DateTime.Now.TimeOfDay == TimeSpan.FromHours(6)) {
snplayer.play();
}
Warning: You may still find
sndplayer.play()
will never execute! Can you guess why?
/ravi