Merge pull request #4489 from OmrSi/switch-getting-chapters-to-task-run

Use Task.Run and await in getting chapters
This commit is contained in:
Nikolaj Olsson 2020-11-10 12:00:52 +01:00 committed by GitHub
commit 20db88a0aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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<MatroskaChapter>();
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)