diff --git a/src/Forms/Main.cs b/src/Forms/Main.cs index 9851d53a3..31dbe8b80 100644 --- a/src/Forms/Main.cs +++ b/src/Forms/Main.cs @@ -27084,42 +27084,35 @@ namespace Nikse.SubtitleEdit.Forms } } - private void toolStripMenuItemImportChapters_Click(object sender, EventArgs e) + private async void toolStripMenuItemImportChapters_Click(object sender, EventArgs e) { toolStripMenuItemImportChapters.Enabled = false; ShowStatus(_language.ImportingChapters); var chaps = new List(); - var getChapters = System.Threading.Tasks.Task.Factory.StartNew(() => + using (var matroska = new MatroskaFile(VideoFileName)) { - using (var matroska = new MatroskaFile(VideoFileName)) - { - chaps = matroska.GetChapters(); - } - }); + chaps = await System.Threading.Tasks.Task.Run(() => matroska.GetChapters()); + } - var uiContext = System.Threading.Tasks.TaskScheduler.FromCurrentSynchronizationContext(); - getChapters.ContinueWith(_ => + if (chaps?.Count > 0) { - if (chaps?.Count > 0) - { - mediaPlayer.Chapters = chaps; + mediaPlayer.Chapters = chaps; - if (audioVisualizer.WavePeaks != null) - { - audioVisualizer.Chapters = chaps; - } - - ShowStatus(string.Format(_language.XChaptersImported, chaps?.Count)); - } - else + if (audioVisualizer.WavePeaks != null) { - ShowStatus(_language.NoChapters); - MessageBox.Show(_language.NoChapters, Title); + audioVisualizer.Chapters = chaps; } - toolStripMenuItemImportChapters.Enabled = true; - }, uiContext); + ShowStatus(string.Format(_language.XChaptersImported, chaps?.Count)); + } + else + { + ShowStatus(_language.NoChapters); + MessageBox.Show(_language.NoChapters, Title); + } + + toolStripMenuItemImportChapters.Enabled = true; } private void toolStripMenuItemImportSceneChanges_Click(object sender, EventArgs e)