private void Form1_FormClosing(object sender, FormClosingEventArgs e) { isClosing = true; this.Hide(); smng.RemoveAll <string>(SettingsConstants.URL); var lineQuery = queueingUrls.Lines .SkipWhile(x => string.IsNullOrEmpty(x)) .Reverse() .SkipWhile(x => string.IsNullOrEmpty(x)) .Reverse(); foreach (string line in lineQuery) { smng.AddItem(SettingsConstants.URL, line); } pollingTimer.Stop(); if (downloadWorker.IsBusy) { smng.AddItem(SettingsConstants.URL, downloadWorker.WatchUrl); SaveSettings(); downloadWorker.CancelAsync(); } else { SaveSettings(); } while (downloadWorker.IsBusy) { Thread.Sleep(1 * 1000); } logWriter.Dispose(); }