1>引用
using System.Threading;using System.Threading.Tasks;2> 方法1 Export_Ex()
public void Export_Ex() { try { this.m_TokenCancel = new CancellationTokenSource(); this.m_Task = new Task(() => this.exportPRocess(this.m_TokenCancel.Token), this.m_TokenCancel.Token); this.m_Task.Start(); //this.m_Task.Wait(); } catch (Exception) { } }3>方法2 exportProcess(CancellationToken token)
private void exportProcess(CancellationToken token) { try { if (null == token || true == token.IsCancellationRequested) { throw new OperationCanceledException(token); } else { //@! 业务代码 线程里要跑的代码 } } catch(Exception ) { } }4>调用方法 btnTest_Click(object sender, EventArgs e)
private void btnTest_Click(object sender, EventArgs e) { this.Export_Ex(); }新闻热点
疑难解答