private void MiChannelSettingsClick(object sender, EventArgs e) { // prevent opening multiple dialogs at the same time EnableContextMenuDialogs(false); // disable timers retrieveTimer.Stop(); dispTimer.Stop(); // cancel potential background worker operation retriever.backgroundWorker.CancelAsync(); // show the settings form FormChannelSettings formChannelSettings = new FormChannelSettings(null); DialogResult result = formChannelSettings.ShowDialog(); // we must renable the menu items before UpdateIcon() EnableContextMenuDialogs(true); if (result == DialogResult.OK) { // restore icon properties UpdateIcon(); // setup new rss list // since we modified the channel settings file, there must not be an exception retriever.InitializeChannels(); } // start background worker thread to retrieve channels if (!isPaused) { // we might get a race condition here, if the worker thread is still not cancelled! if (retriever.backgroundWorker.IsBusy == false) { // worker already finished, everything fine retriever.backgroundWorker.RunWorkerAsync(); } else { // work still pending, we cannot restart right now // in this case, we start the retriever timer and // hope that the worker is finished before the timer expires! retrieveTimer.Start(); } } }
// constructor of main form public FormMain() { // setup GUI InitializeComponent(); // setup display timer dispTimer = new Timer(); dispTimer.Tick += new EventHandler(OnDispTimerTick); dispTimer.Enabled = false; dispTimer.Interval = Settings.Default.displayIntervall * 60 * 1000; // intervall in min // setup retrieve timer retrieveTimer = new Timer(); retrieveTimer.Tick += new EventHandler(OnRetrieverTimerTick); retrieveTimer.Enabled = false; retrieveTimer.Interval = Settings.Default.retrieveIntervall * 60 * 1000; // intervall in min // setup single click timer doubleClickTimer = new Timer(); doubleClickTimer.Tick += new EventHandler(OnDoubleClickTimerTick); doubleClickTimer.Enabled = false; doubleClickTimer.Interval = SystemInformation.DoubleClickTime / 2; // setup and start the background worker retriever = new Retriever(); retriever.backgroundWorker.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(this.RetrieveCompleted); retriever.backgroundWorker.ProgressChanged += new System.ComponentModel.ProgressChangedEventHandler(this.RetrieverProgressError); // set initial status isPaused = Settings.Default.startPaused; // set icon and tooltip text UpdateIcon(); // read channel settings bool firstStart = retriever.InitializeChannels(); if (firstStart) { // display welcome message applicationIcon.ShowBalloonTip( Settings.Default.balloonTimespan * 1000, Resources.str_balloonWelcomeHeader, Resources.str_balloonWelcomeBody, ToolTipIcon.Info); } // check command line args to potentially subscribe to a feed foreach (string cmdLineArg in Environment.GetCommandLineArgs()) { if (Uri.IsWellFormedUriString(cmdLineArg, UriKind.Absolute)) { // show the settings form FormChannelSettings formChannelSettings = new FormChannelSettings(cmdLineArg); formChannelSettings.ShowDialog(); // fixme: we can only add a single channel break; } } // load initial channels in background task if (!isPaused) { retriever.backgroundWorker.RunWorkerAsync(); } }