我正在为我的WPF应用程序添加一个进度条。我想告诉与生成文件的实时计数一起在进度条上的实时进展情况等产生4/100文件等下面是这两个动作和任务正在执行这些行动WPF实时进度条
Action Generate = new Action(() =>
{
foreach (string file in Files)
{
//all the logic to generate files
using (var streamWriter = new StreamWriter(newFileName, false, Encoding.Default))
{
foreach (string segment in newFile)
{
streamWriter.WriteLine(segment);
}
filesGenerated++;
//I need to do the second action here
}
}
});
Action ShowProgressBar = new Action(() =>
{
progressBar.Value = filesGenerated
lblProgress.Content = filesGenerated + " File(s) Generated.";
});
Task GenerateTask = Task.Factory.StartNew(() => Generate());
Task ShowProgressBarTask = new Task(ShowProgressBar);
我试图嵌套的任务,但它不工作。我应该做些什么来显示实时进度条。
请使用扩展WPF工具包,它具有BusyIndicator控件元素:CodePlex项目(http://wpftoolkit.codeplex.com/)BusyIndicator控件文件](http://wpftoolkit.codeplex.com/wikipage?title=BusyIndicator&referringTitle=Home) – Rumplin 2011-08-17 12:43:18