Friday, August 29, 2014

Play a sound when the application closes in C#

How do you play a sound (from Resources) when the application closes?


I'm using the code below, but it seems to play the sound twice instead of once...



System.Media.SoundPlayer player = new System.Media.SoundPlayer();

player.Stream = Properties.Resources.<soundname>;
player.Play();

System.Threading.Thread.Sleep(2000);
Application.Exit();

I use System.Threading.Thread.Sleep(2000); because if I don't the application will just quit without playing the sound.


Can anyone solve the problem?




---- JDS404 ---- Check out my blog at http://ift.tt/SaWROI!


No comments:

Post a Comment