日期:2014-05-17 浏览次数:20970 次
public void OnProcessCompleted(object sender, EventArgs e) { this.Close(); } public void OnProgressChanged(object sender, ProgressChangedEventArgs e) { progressBar1.Value = e.ProgressPercentage; }
public partial class Form1 : Form { private BackgroundWorker worker = null; private void radioButton2_CheckedChanged(object sender, EventArgs e) { if (radioButton2.Checked) { frmPross pross = new frmPross(); pross.Show(); worker = new BackgroundWorker(); worker.WorkerReportsProgress = true; worker.WorkerSupportsCancellation = true; worker.DoWork += new DoWorkEventHandler(rb2_checked); worker.ProgressChanged += new ProgressChangedEventHandler(pross.OnProgressChanged); worker.ProgressChanged += new ProgressChangedEventHandler(。。。) worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(pross.OnProcessCompleted); worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(。。。); worker.RunWorkerAsync(。。。) } else { //初始化表格样式,清除单元格数值 } } private void rb2_checked(object sender, EventArgs e) { //单元格样式、大量单元格数值计算 }
private void moveButton_Click(object sender, EventArgs e) { //Show the progress bar ProgressForm progressForm = new ProgressForm(); progressForm.Show(); worker= new BackgroundWorker(); // Specify that the background worker provides progress notifications worker.WorkerReportsProgress = true; // Specify that the background worker supports cancellation worker.WorkerSupportsCancellation = true; // The DoWork event handler is the main work function of the background thread worker.DoWork += new DoWorkEventHandler(worker_DoWork); // Specify the function to use to handle progress worker.ProgressChanged += new ProgressChangedEventHandler(worker_ProgressChanged); worker.ProgressChanged += new ProgressChangedEventHandler(progressForm.OnProgressChanged); // Specify the function to run when the background worker finishes // There are three conditions possible that should be handled in this function: // 1. The work completed successfully // 2. The work aborted with errors // 3. The user cancelled the process worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(worker_RunWorkerCompleted); worker.RunWorkerCompleted+=new RunWorkerCompletedEventHandler(progressForm.OnProcessCompleted); //If your background operation requires a parameter, //call System.ComponentModel.BackgroundWorker.RunWorkerAsync //with your parameter. Inside the System.ComponentModel.BackgroundWorker.DoWork //event handler, you can extract the parameter from the //System.ComponentModel.DoWorkEventArgs.Argument property. worker.RunWorkerAsync(leftList); } private void worker_DoWork(object sender, DoWorkEventAr