mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-11-26 05:02:36 +01:00
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:
commit
20db88a0aa
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user