// 读取数据响应进度条 private void log_ValueChanged(object sender, ValueEventArgs e) { System.Windows.Forms.MethodInvoker invoke = () => { double v = (double)e.CurrentStep / (double)e.TotalStep; if (v < 0) { v = 0; } if (v > 1) { v = 1; } gridViewGroupList.SetRowCellValue(rowHandle, "读取进度", (v * 100.0).ToString("f1")); }; if (this.InvokeRequired) { this.BeginInvoke(invoke); } else { invoke(); } }
public RASProperties() { InitializeComponent(); t = new Timer(); t.Interval = 500; t.Tick += new EventHandler(t_Tick); t.Start(); logMiv = new MethodInvoker(UpdateLog); }
private void startPlay() { System.Windows.Forms.MethodInvoker merr = new System.Windows.Forms.MethodInvoker(qz._OnError); try { if (qz.Loaded) { System.Windows.Forms.MethodInvoker mi = null; if (!qz.Loop) { mi = new System.Windows.Forms.MethodInvoker(qz._OnFinish); } qz._Run(); while (!bCancel) { if (qz.Finished) { if (qz.Loop) { qz.ToBeginPos(); qz._Run(); } else { if (!bCancel) { qz.BeginInvoke(mi); } break; } } Application.DoEvents(); } } } catch (System.Runtime.InteropServices.ExternalException ei) { if (ei.ErrorCode != -2147220953) { if (!bCancel) { qz.sErrMsg = ei.Message; qz.BeginInvoke(merr); } } } catch (Exception er) { if (!bCancel) { qz.sErrMsg = er.Message; qz.BeginInvoke(merr); } } }
private void SetMax(object sender, int max) { //this.toolStripProgressBar1.Maximum = max; System.Windows.Forms.MethodInvoker invoker = () => { this.tssProcess.Maximum = max; }; if (this.statusStrip1.InvokeRequired) { this.statusStrip1.Invoke(invoker); } else { invoker(); } }
/// <summary> /// Invoke action delegate on main thread if required. /// </summary> /// <param name="obj">Object to check for InvokeRequired</param> /// <param name="action">Action delegate to perform (either on the current thread or invoked).</param> /// <remarks> /// Extension for any object that supports the ISynchronizeInvoke interface (such as WinForms /// controls). This will handle the InvokeRequired check and call the action delegate from /// the appropriate thread. /// </remarks> /// <example> /// <code> /// <![CDATA[ /// private void DB_OfflineModeChanged(object sender, Lib.DB.OfflineModeEventArgs e) /// { /// // This code could be ran from a background thread /// this.InvokeIfRequired(() => /// { /// // Code to run after invoking if required /// OfflineStatusLabel.Visible = e.OfflineMode; /// }); /// } /// ]]> /// </code> /// </example> public static void InvokeIfRequired(this ISynchronizeInvoke obj, System.Windows.Forms.MethodInvoker action) { if (obj.InvokeRequired) { var args = new object[0]; try { obj.Invoke(action, args); } catch { } } else { action(); } }
private void ShowProcess(object sneder, int value, string status) { System.Windows.Forms.MethodInvoker invoker = () => { this.tssProcess.Value = value; this.tssMsg.Text = (((float)value) / this.tssProcess.Maximum).ToString("0.00%"); this.StatusMsg.Text = value + "/" + this.tssProcess.Maximum; this.tssStatus.Text = status; }; if (this.statusStrip1.InvokeRequired) { this.statusStrip1.Invoke(invoker); } else { invoker(); } if (value == this.tssProcess.Maximum) { System.Windows.Forms.MethodInvoker invoker1 = () => { this.btnImport.Enabled = true; }; if (this.btnImport.InvokeRequired) { this.btnImport.Invoke(invoker1); } else { invoker1(); } System.Windows.Forms.MethodInvoker invoker3 = () => { this.btnCen.Enabled = false; }; if (this.btnCen.InvokeRequired) { this.btnCen.Invoke(invoker3); } else { invoker3(); } } }
private void refreshForm(object data) { Form frm = this.FindForm(); if (frm != null && frm.Handle != IntPtr.Zero && !frm.IsDisposed && !frm.Disposing) { if (frm.InvokeRequired) { System.Windows.Forms.MethodInvoker mi = new System.Windows.Forms.MethodInvoker(frm.Refresh); frm.BeginInvoke(mi); } else { frm.Refresh(); } } }
/// <summary> /// 进度发生变化之后的回调方法 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void workder_ValueChanged(object sender, ValueEventArgsloading e) { try { System.Windows.Forms.MethodInvoker invoker = () => { // 打开进度条 if (e.Value == 1) //开始 { setTime(progressBar1, 0, dataCountAll); } else if (e.Value == 2) //结束 { //progressBar1.Value = 100; //将信息设定到页面中 //SetControlTextStr(label_jd, "100"); if (t != null) { t.Abort(); } } else if (e.Value == 3) //初始化 { t.Abort(); setTime(progressBar1, 0, dataCountAll); } }; if (this.InvokeRequired) { this.Invoke(invoker); } else { invoker(); } } catch (Exception ex) { string ss = ex.Message; } }
/// <summary> /// 数据下载结束异步操作 /// </summary> /// <param name="ar"></param> public void AsyncCallback(IAsyncResult ar) { // 标准的处理步骤 Action handler = ar.AsyncState as Action; handler.EndInvoke(ar); System.Windows.Forms.MethodInvoker invoker = () => { if (ResultStatus.Equals("0")) { //progressBar1.Value = 0; ////下载完成后调用数据导入处理 //dataImport(); MessageBox.Show("下载导入完成!"); } else if (ResultStatus.Equals("4")) { MessageBox.Show(ResultStr); } else { MessageBox.Show(ResultStr); } this.ResultStatus = "7"; }; if (this.InvokeRequired) { this.Invoke(invoker); } else { invoker(); } }
public void Invoke(System.Windows.Forms.MethodInvoker invoker) { Invoke((Delegate)invoker); }
private void ShowProcess(object sneder, int value, int skip, int overwirte, string status) { System.Windows.Forms.MethodInvoker invoker = () => { this.tssProcess.Value = value; this.tssMsg.Text = (((float)value) / this.tssProcess.Maximum).ToString("0.00%"); this.StatusMsg.Text = value + "/" + this.tssProcess.Maximum; this.tssStatus.Text = status; if (status == "导入完毕") { BLL.DBLinq.ZTHelper.UpdataSum(ztid); string message; if (rbSkip.Checked) { message = string.Format("导入完毕,共:[{0}] 条记录,成功:[{1}]条,跳过:{2}条,\n是否进行专利浏览", this.tssProcess.Maximum, value, skip); } else { message = string.Format("导入完毕,共:[{0}] 条记录,成功:[{1}]条,覆盖:{2}条,\n是否进行专利浏览", this.tssProcess.Maximum, value, overwirte); } if (MessageBox.Show(this, message, "导入完毕", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes) { //inifilter(ztid); try { frmPtList frmdbin = new frmPtList(strname, ztid, type); frmdbin.MdiParent = this.MdiParent; frmdbin.Show(); this.Close(); } catch (Exception) { } } else { if (value == this.tssProcess.Maximum) { System.Windows.Forms.MethodInvoker invoker1 = () => { this.btnImport.Enabled = true; }; if (this.btnImport.InvokeRequired) { this.btnImport.Invoke(invoker1); } else { invoker1(); } } } } }; if (this.statusStrip1.InvokeRequired) { this.statusStrip1.Invoke(invoker); } else { invoker(); } }
private void Window_Loaded(object sender, RoutedEventArgs e) { #region Регистрация горячих клавиш Formms.MethodInvoker mi = new Formms.MethodInvoker(WaitKey); mi.BeginInvoke(null, null); #endregion Window window = Window.GetWindow(this); var wih = new WindowInteropHelper(window); IntPtr hWnd = wih.Handle; if (TaskbarManager.IsPlatformSupported) TaskbarManager.Instance.ThumbnailToolBars.AddButtons (hWnd, buttonPrevious, buttonPlayPause, buttonNext); }