public void StartSubtitles() { try { if (_subtitles.Count.Equals(0)) { return; } SubtitleBackgroundWorker.RunWorkerAsync(); } catch (System.Exception) { // didnt wait much time. } }
private void SubtitleBackgroundWorkerDoWork(object sender, DoWorkEventArgs e) { TimeSpan delta = new TimeSpan(); foreach (Subtitle subtitle in _subtitles.Values) { // wait for next text to appear Thread.Sleep(subtitle.StartTime - delta); // update delta delta = subtitle.StartTime; // set text _text = subtitle.Text; // fake report just to force main thread to send new text SubtitleBackgroundWorker.ReportProgress(0); // wait for text exit Thread.Sleep(subtitle.EndTime - delta); // update delta delta = subtitle.EndTime; // remove text _text = string.Empty; // fake report just to force main thread to send new text SubtitleBackgroundWorker.ReportProgress(0); // if cancel, leave if (SubtitleBackgroundWorker.CancellationPending) { e.Cancel = true; return; } } }
public void StopSubtitles() { SubtitleBackgroundWorker.CancelAsync(); }