110,567
社区成员
发帖
与我相关
我的任务
分享
private void button1_Click(object sender, EventArgs e)
{
new System.Threading.Thread(new System.Threading.ThreadStart(Start)).Start();
//旧的代码去掉
}
private void Start()
{
//旧的代码放到这里
}
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);