-1
我有一个方法getPlugins
需要相当长的时间才能运行。本质上它解析了一个非常大的日志文件。我知道日志文件从时间0到时间24.我想根据当前时间更新ProgressBar
。这里是我的代码的结构,但只有当我的循环完成后,条才会更新......我该如何解决这个问题?更新循环中的进度栏
private void getPlugins(String filePath)
{
var w = new Window2();
w.Show();
w.progress.Value = 0;
List<String> pluginNames = new List<String>();
string strLine;
// Read the file and display it line by line.
System.IO.StreamReader file = new System.IO.StreamReader(filePath);
while ((strLine = file.ReadLine()) != null)
{
// Do stuff....
float time; // Here I have time as a float from 0 to 24
w.progress.Value = time;
}
file.Close();
w.progress.Value = 24;
w.Close();
}
出现这种情况的原因是因为你的努力更新和处理在UI线程上的文件。您需要创建一个线程来处理该文件,然后看到如何更新进度条以下内容http://stackoverflow.com/questions/6036279/wpf-progress-bar-update-with-dispatcher – 3dd
请参阅此链接](http://stackoverflow.com/questions/12676490/progress-bar-not-progressing)和[this](http://www.dotnetcurry.com/ShowArticle.aspx?ID=571)调度员和后台工作者。 – learningNew
http://stackoverflow.com/questions/6365887/can-you-link-to-a-good-example-of-using-backgroundworker-without-placing-it-on-a/6365951#6365951 – CharithJ