public WindowAudio(UserAudio audio) { InitializeComponent(); this.Closing += (s, e) => { ClearObjects(); }; client = new WebClient(); if (audio != null) userAudio = audio; }
private void ClearObjects() { IsClosingWind = true; if (!client.IsNull()) { if (client.IsBusy) client.CancelAsync(); client.DownloadDataCompleted -= client_DownloadDataCompleted; client.DownloadProgressChanged -= client_DownloadProgressChanged; client.Dispose(); client = null; } userAudio = null; if (player != null) { player.Close(); player = null; } if (!string.IsNullOrEmpty(CurrentAudio)) System.IO.File.Delete(CurrentAudio); DialogResult = false; }