using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using Sys ...
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Draget='_blank'>wing;using System.Linq;using System.Text;using System.Threading;using System.Windows.Forms;namespace WinformTest{ public partial class frmMain : Form { public frmMain() { InitializeComponent(); } #region 运用线程 /// <summary> /// 导出Excel或其他耗时计算 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnExport_Click(object sender, EventArgs e) { //显示正在计算的动画 this.pictureBox1.Visible = true; //启用另一个线程,完成导出 Thread t = new Thread(new ParameterizedThreadStart(Export)); t.Start("sql where"); } /// <summary> /// 这里以有参举例 /// </summary> /// <param name="strWhere"></param> private void Export(object strWhere) { Thread.Sleep(1000); this.Invoke(new Action(UpdateUI)); } private void UpdateUI() { this.pictureBox1.Visible = false; } #endregion #region 运用线程池,同时有返回值 private void btnExportAnother_Click(object sender, EventArgs e) { //显示正在计算的动画 this.pictureBox1.Visible = true; //使用线程池,来完成导出 WaitCallback wc = new WaitCallback(this.ExportExcel); ThreadPool.QueueUserWorkItem(wc, "sql where"); } private void ExportExcel(object sql) { Thread.Sleep(1000); //这里还以有参举例 object result = this.Invoke(new Func<int, int>(GetNumber), 11); MessageBox.Show(result + ""); } private int GetNumber(int num) { this.pictureBox1.Visible = false; return 1111; } #endregion private void btnTest_Click(object sender, EventArgs e) { MessageBox.Show("能操作界面"); } }}
海外公司注册、海外银行开户、跨境平台代入驻、VAT、EPR等知识和在线办理:https://www.xlkjsw.com
原标题:导出Excel 或 大量耗时计算时,前端界面保持可操作
关键词:前端
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们:
admin#shaoqun.com
(#换成@)。