本文介绍了C#.net中的进度条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用backgroundWorker事件处理进度条,同时将数据复制到另一个磁盘?如何处理backgroundWorker进程?

How to handle progress bar using backgroundWorker events while copy data one disk to another??How to handle backgroundWorker process?

推荐答案


    BackgroundWorker worker = new BackgroundWorker();
    worker.WorkerReportsProgress = true;
    worker.ProgressChanged += new ProgressChangedEventHandler(worker_ProgressChanged);
    worker.DoWork += new DoWorkEventHandler(worker_DoWork);
    worker.RunWorkerAsync();
    ...

void worker_ProgressChanged(object sender, ProgressChangedEventArgs e)
    {
    myProgressBar.Value = e.ProgressPercentage;
    }

void worker_DoWork(object sender, DoWorkEventArgs e)
    {
    BackgroundWorker work = sender as BackgroundWorker;
    for (int i = 0; i < 100; i++)
        {
        // Do something
        work.ReportProgress(i);
        }
    }


这篇关于C#.net中的进度条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 17:43