我正在使用库中的函数来处理非常大的单词文件,我无法更改此功能.
在处理时,我想显示一个进度条,因为无论哪种方式,应用程序看起来都冻结了,用户也不知道它实际上正在工作.
现在我正在使用这样的工人:
在处理时,我想显示一个进度条,因为无论哪种方式,应用程序看起来都冻结了,用户也不知道它实际上正在工作.
现在我正在使用这样的工人:
private void btnClick(object sender,RoutedEventArgs e) { BackgroundWorker worker = new BackgroundWorker(); worker.RunWorkerCompleted += worker_RunWorkerCompleted; worker.WorkerReportsProgress = true; worker.DoWork += worker_DoConvertOne; worker.ProgressChanged += worker_ProgressChanged; worker.RunWorkerAsync(); } private void worker_DoConvertOne(object sender,DoWorkEventArgs e) { var worker = sender as BackgroundWorker; //The progress bar is filled on 20% worker.ReportProgress(0); worker.ReportProgress(10); worker.ReportProgress(20); //Processing myLongLastingFunction(bigWordFile); //The progress bas is full worker.ReportProgress(100,"Done Processing."); } private void worker_RunWorkerCompleted(object sender,RunWorkerCompletedEventArgs e) { MessageBox.Show("Converting finished!"); TestProgressBar.Value = 0; ProgressTextBlock.Text = ""; } private void worker_ProgressChanged(object sender,ProgressChangedEventArgs e) { TestProgressBar.Value = e.ProgressPercentage; ProgressTextBlock.Text = (string)e.UserState; }