void DownloadCenterForm_FormClosing(object sender, FormClosingEventArgs e) { if (!trayIconExit) { e.Cancel = true; Hide(); notifyIcon1.Visible = true; return; } if (MTDOList.Any(x => x.dorg.IsActive)) { flagCloseAfterStop = true; e.Cancel = true; foreach (var item in MTDOList) { item.dorg.Stop(); item.dorg.Stopped += dorg_Stopped; } } else { saveDownloadList(); notifyIcon1.Visible = false; notifyIcon1.Icon = null; notifyIcon1.Dispose(); notifyIcon1 = null; } }
void dorg_Stopped(object sender, EventArgs e) { if (flagCloseAfterStop && !MTDOList.Any(x => x.dorg.IsActive) && trayIconExit) { flagCloseAfterStop = false; saveDownloadList(); notifyIcon1.Visible = false; notifyIcon1.Icon = null; notifyIcon1.Dispose(); this.Close(); } }