private void ProgramIsRunning(string subtitle, string subtitle2) { if (this.SubtitleDisplayBox.InvokeRequired) { SubtitleDisplayBox.Invoke(new MethodInvoker(delegate { SubtitleDisplayBox.Text = subtitle; })); SubtitleBox2.Invoke(new MethodInvoker(delegate { SubtitleBox2.Text = subtitle2; })); } }
public void MainOperation(Dictionary <int, string> SubtitleDictionary, int totalTime, Dictionary <int, string> subtitleDictionary2) { if (moreThanOne) { SubtitleBox2.Invoke(new MethodInvoker(delegate { SubtitleBox2.Show(); })); } Stopwatch timer1 = new Stopwatch(); timer1.Start(); while (timer1.IsRunning) { Thread.Sleep(1000); TimeSpan tsLeadIn = timer1.Elapsed; if (tsLeadIn.Seconds == 1) { ProgramIsCountingDown("3"); } if (tsLeadIn.Seconds == 2) { ProgramIsCountingDown("2"); } if (tsLeadIn.Seconds == 3) { ProgramIsCountingDown("1"); } if (tsLeadIn.Seconds == 4) { ProgramIsCountingDown("PLAY"); timer1.Stop(); } } string printingSubtitle; string printingSubtitle2 = null; Stopwatch timer = new Stopwatch(); timer.Start(); TimeSpan monitorTotalTime = new TimeSpan(); while (monitorTotalTime.Seconds * 1000 != totalTime) { if (!(this.isPaused)) { if (!(timer.IsRunning)) { timer.Start(); } Thread.Sleep(250); TimeSpan ts = timer.Elapsed; int currentTime = (((ts.Minutes * 60) + (ts.Seconds)) * 1000); if (currentTime == 2000) { ProgramIsDoneCountingDown(); } if (SubtitleDictionary.TryGetValue(currentTime, out printingSubtitle)) { if (subtitleDictionary2 != null) { subtitleDictionary2.TryGetValue(currentTime, out printingSubtitle2); } ProgramIsRunning(printingSubtitle, printingSubtitle2); } } if (this.isPaused) { if (timer.IsRunning) { timer.Stop(); } Thread.Sleep(250); } } }