private void backgroundWorkerShow_DoWork(object sender, DoWorkEventArgs e) { System.Threading.Thread.CurrentThread.Priority = System.Threading.ThreadPriority.AboveNormal; CrossThreadHelper.SetCrossThreadProperty(this, "Visible", true); CrossThreadHelper.CallCrossThreadMethod(this, "Show", null); CrossThreadHelper.SetCrossThreadProperty(this, "Top", ScreenBottom); CrossThreadHelper.SetCrossThreadProperty(this, "Left", SystemInformation.WorkingArea.Width - this.Width - 10); int delta = this.Height / 100; double opacity = this.Opacity; while (this.Top > ScreenBottom - this.Height) { int top = this.Top - delta; CrossThreadHelper.SetCrossThreadProperty(this, "Top", top); this.Invalidate(); Application.DoEvents(); System.Threading.Thread.Sleep(5); } double fadeDelta = OpacityFinal / (FadeInTime / 10); while (this.Opacity < OpacityFinal) { opacity += fadeDelta; // 0.01; CrossThreadHelper.SetCrossThreadProperty(this, "Opacity", opacity); CrossThreadHelper.CallCrossThreadMethod(this, "Invalidate", null); System.Threading.Thread.Sleep(10); } LastActivatedTime = DateTime.Now; FullyDisplayed = true; this.Invalidate(); }
private void RefreshServersAsync() { Font originalFont = comboBoxServers.Font; try { string[] registeredServerNames = new string[0]; switch (DatabaseType) { case DatabaseTypes.SQLServer2000: registeredServerNames = ArchAngel.Providers.Database.SQLServerDAL_2005.SQLServer.GetSqlServers(); break; case DatabaseTypes.SQLServer2005: registeredServerNames = ArchAngel.Providers.Database.SQLServerDAL_2005.SQLServer.GetSqlServers(); break; case DatabaseTypes.SQLServerExpress: registeredServerNames = ArchAngel.Providers.Database.SQLServerDAL_Express.SQLServer.GetSqlServers(); break; default: MessageBox.Show("This type of database is not yet handled: " + DatabaseType.ToString()); break; } CrossThreadHelper.CallCrossThreadMethod(comboBoxServers.Items, "Clear", null); CrossThreadHelper.SetCrossThreadProperty(comboBoxServers, "Text", ""); CrossThreadHelper.SetCrossThreadProperty(comboBoxServers, "Font", originalFont); CrossThreadHelper.SetCrossThreadProperty(comboBoxServers, "ForeColor", Color.Black); foreach (string server in registeredServerNames) { CrossThreadHelper.CallCrossThreadMethod(comboBoxServers.Items, "Add", new object[] { server }); } if (comboBoxServers.Items.Count > 0) { CrossThreadHelper.SetCrossThreadProperty(comboBoxServers, "SelectedIndex", 0); } } catch (Exception) { CrossThreadHelper.SetCrossThreadProperty(comboBoxServers, "Text", ""); CrossThreadHelper.SetCrossThreadProperty(comboBoxServers, "Font", originalFont); CrossThreadHelper.SetCrossThreadProperty(comboBoxServers, "ForeColor", Color.Black); //Common.ReportError(ex); } finally { CrossThreadHelper.SetCrossThreadProperty(this, "Cursor", Cursors.Default); } }
public void IncrementProgress(int i) { ProgressBar progBar = (ProgressBar)ProgressBars[i]; Label statusLabel = (Label)StatusLabels[i]; Label descriptionLabel = (Label)DescriptionLabels[i]; if (progBar.InvokeRequired) { if (progBar.Value >= progBar.Minimum) { CrossThreadHelper.SetCrossThreadProperty(progBar, "Visible", true); CrossThreadHelper.SetCrossThreadProperty(statusLabel, "Visible", false); CrossThreadHelper.SetCrossThreadProperty(descriptionLabel, "Visible", false); } CrossThreadHelper.CallCrossThreadMethod(progBar, "Increment", new object[] { 1 }); if (progBar.Value == progBar.Maximum) { CrossThreadHelper.SetCrossThreadProperty(progBar, "Visible", false); CrossThreadHelper.SetCrossThreadProperty(descriptionLabel, "Visible", false); if (progBar.Value != 1) { CrossThreadHelper.SetCrossThreadProperty(statusLabel, "Text", string.Format("Complete - {0} files.", progBar.Value)); } else { CrossThreadHelper.SetCrossThreadProperty(statusLabel, "Text", "Complete - 1 file."); } CrossThreadHelper.SetCrossThreadProperty(statusLabel, "Visible", true); } } else { if (progBar.Value == progBar.Minimum) { progBar.Visible = true; statusLabel.Visible = false; descriptionLabel.Visible = true; } progBar.Increment(1); if (progBar.Value == progBar.Maximum) { progBar.Visible = false; descriptionLabel.Visible = false; if (progBar.Value != 1) { statusLabel.Text = string.Format("Complete - {0} files.", progBar.Value); } else { statusLabel.Text = "Complete - 1 file."; } statusLabel.Visible = true; } } }