I'm trying to make a "notification sound" that plays at certain time specified in the app, but for some reason it won't work. If I compare against a time interval it keeps playing the sound in a loop, but I cannot get it to play the sound once at the very moment the time matches.
System.Media.SoundPlayer player = new System.Media.SoundPlayer(@"c:\Windows\Media\ding.wav");
private void timer1_Tick(object sender, EventArgs e)
{
TimeSpan currentTime = DateTime.Now.TimeOfDay;
if (currentTime == TimeSpan.Parse("15:00"))
{
player.Play();
}
}
The timer compares current time every 100ms so I don't think it's down to timing but maybe I'm just missing something. Any ideas what's wrong or if I should use a different approach?