Example #1
0
        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;
            }
        }