private async void Play_SoundAsync(object sender, EventArgs e) { LinkLabel b = (LinkLabel)(sender); try { if (b.Text == "Sound") { b.Text = "Stop"; Panel p = (Panel)b.Parent.Parent.Parent; foreach (LinkLabel l in Helper.GetAll(p, b.GetType()).Where(a => a.Text != "Detail" && a != b)) { l.Text = "Sound"; } disposeWave(); await GetWave((int)b.Tag); if (waveOutDevice == null) { waveOutDevice = new WaveOut(); } if (audioFileReader == null) { audioFileReader = new AudioFileReader(@"video.wav"); } waveOutDevice.Init(audioFileReader); waveOutDevice.PlaybackStopped += (send, args) => AutoPlaySoundAsync(send, args, (int)b.Tag); waveOutDevice.Play(); } else { b.Text = "Sound"; waveOutDevice?.Stop(); audioFileReader?.Dispose(); waveOutDevice?.Dispose(); audioFileReader = null; waveOutDevice = null; } } catch (Exception ex) { //MessageBox.Show(ex.Message); //throw; Action action = () => { b.BackColor = Color.Red; }; b.SafeInvoke(action, true); } }