在c# WinForm程序中关闭程序的同时停止BackgroundWork

来自:http://outofmemory.cn/code-snippet/1773/c-WinForm-program-guanbichengxu-tongshi-stop-BackgroundWork

在form关闭的同时停止BackgroundWork:

protected override void OnFormClosing(FormClosingEventArgs e) {
    if (!mCompleted && ) {
        backgroundWorker1.CancelAsync();
        this.Enabled = false;
        e.Cancel = true;
        mClosePending = true;
    }
}

void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) {
    mCompleted = true;
    if (mClosePending) this.Close();
}


你可能感兴趣的:(WinForm程序)