System.Media.SoundPlayer player = new System.Media.SoundPlayer(); player.LoadAsync("backgroundMusic.wav"); // asynchronously load the background music
using System.IO; using System.Media; class Program { static void Main(string[] args) { SoundPlayer player = new SoundPlayer(); player.LoadAsync(new MemoryStream(File.ReadAllBytes("soundEffect.wav"))); } }This code reads a sound file named "soundEffect.wav", converts it to a byte array, and uses a MemoryStream object to asynchronously load the sound file. The System.Media.SoundPlayer.LoadAsync method is part of the .NET Framework Class Library and does not require any additional package or library to use.