public async Task TaskExport(string TableName, string sql, string filename) { await Task.Run(() => { int time = UiServices.ExportExcel("Sheet1", sql, filename); string s = string.Format("导出的时间为:{0}秒", time); this.BeginInvoke(new System.EventHandler(ShowMessage), s); //MessageBox.Show("导数已完成!"); GC.Collect(); }); }
private void button3_Click(object sender, EventArgs e) { if (textBox2.Text.ToString() == "") { MessageBox.Show("请选择需要导入的文件夹!"); } DataTable[] ds = UiServices.GetDataTableFromCSV(this.textBox2.Text.ToString(), true); string filename = UiServices.ShowFileDialog("Book1"); int time = UiServices.ExportExcel(ds, filename); GC.Collect(); toolStripStatusLabel1.Text = string.Format("执行操作时间为:{0}秒", time); toolStripStatusLabel1.ForeColor = Color.Red; }
//异步导出EXCEL public async Task TaskExport(IList <string> SheetNames, string filename) { await Task.Run(() => { try { int time = UiServices.ExportExcel(SheetNames, filename); string s = string.Format("导出的时间为:{0}秒", time); this.BeginInvoke(new System.EventHandler(ShowMessage), s); MessageBox.Show("导数已完成!"); GC.Collect(); } catch (Exception ee) { this.BeginInvoke(new System.EventHandler(ShowErr), ee); return; } }); }