private void bgwFindYouTubeWindows_DoWork(object sender, DoWorkEventArgs e) { ThreadHelperClass.SetVisible(this, progressBar, true); // Stop Timer tmrUpdateCurrentlyPlaying.Enabled = false; ThreadHelperClass.SetEnabled(this, btnFindChromeWindows, false); ThreadHelperClass.SetText(this, btnFindChromeWindows, "Finding non-minimized Chrome windows with YouTube tabs..."); ThreadHelperClass.SetEnabled(this, btnSelectChromeWindow, false); ThreadHelperClass.SetText(this, btnSelectChromeWindow, "2. Select window from list above"); ThreadHelperClass.SetEnabled(this, btnStartStop, false); ThreadHelperClass.SetText(this, btnStartStop, "3. Start"); ThreadHelperClass.SetText(this, lblCurrentlyPlaying, "Stopped"); showTabTitles(); ThreadHelperClass.SetEnabled(this, btnFindChromeWindows, true); ThreadHelperClass.SetText(this, btnFindChromeWindows, "1. Find non-minimized Chrome windows with YouTube tabs"); if (youtubeWindows.Count > 0) { ThreadHelperClass.SetEnabled(this, btnSelectChromeWindow, true); } }
private void bgwUpdateCurrentlyPlaying_DoWork(object sender, DoWorkEventArgs e) { try { ThreadHelperClass.SetVisible(this, progressBar, true); string updatedTabName = GetUpdatedChromeTabTitleFromWindow(selectedYoutubeWindow.Hwnd); if (ThreadHelperClass.GetText(this, btnStartStop) == "3. Stop") { if (String.IsNullOrEmpty(updatedTabName)) { ThreadHelperClass.SetText(this, lblCurrentlyPlaying, "Could not get YouTube title. Is selected window/tab closed? Try starting again from button #1."); try { if (!debug) { System.IO.File.WriteAllText(outputFileName, ""); } else { System.IO.File.AppendAllText(outputFileName, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + ": " + Environment.NewLine); } } catch { ThreadHelperClass.SetText(this, lblCurrentlyPlaying, "Error: Output file is not writeable. Please change output filename under options."); } lastPlayingTitle = null; } else if (lastPlayingTitle != updatedTabName || ThreadHelperClass.GetText(this, lblCurrentlyPlaying) == "Starting...") { lastPlayingTitle = updatedTabName; ThreadHelperClass.SetText(this, lblCurrentlyPlaying, updatedTabName); try { if (!debug) { System.IO.File.WriteAllText(outputFileName, updatedTabName); } else { System.IO.File.AppendAllText(outputFileName, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + ": " + updatedTabName + Environment.NewLine); } } catch { ThreadHelperClass.SetText(this, lblCurrentlyPlaying, "Error: Output file is not writeable. Please change output filename under options."); lastPlayingTitle = null; } } } else { ThreadHelperClass.SetVisible(this, progressBar, false); } } catch when(debug == false) { ThreadHelperClass.SetText(this, lblCurrentlyPlaying, "Could not get YouTube title. Is selected window/tab closed? Try starting again from button #1."); if (!debug) { System.IO.File.WriteAllText(outputFileName, ""); } else { System.IO.File.AppendAllText(outputFileName, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + ": " + Environment.NewLine); } lastPlayingTitle = null; } }