如何在TextBlock和ProgressBar中显示进度?

时间:2016-09-11 14:26:21

标签: c# wpf excel progress-bar

我想展示我的Excel阅读程序的进度。 这里有一些代码:

public void ReadExcel()
    {
    //Do something (get Excel File...)

    txtProgress.Text += "Start";        

    int rows = exRng.Rows.Count;
    int column = exRng.Columns.Count;

    progProgress.Maximum = rows;//ProgressBar
    txtProgress.Text += "Start";//TextBlock

    for (int i = 1; i <= rows; i++)
    {
        progProgress.Value = i;         
        //Do something
        txtProgress.Text += "\n " + Name + " was created";
    }
}

ProgressBar Maximum是excel文件中的行数。在每个循环之后,TextBlock应显示该名称已创建。 ProgressBar值应显示进度。

我的窗口如下: Window with a Textblock at the top and a ProgressBar at the bottom

但窗口仅显示excel阅读的结尾。它不刷新TextBlock或ProgressBar。我只看到空窗口,最后看到这个窗口:End of Progress

有人能帮助我吗? THX

1 个答案:

答案 0 :(得分:1)

您应该使用backgroundWorker来实现此目的。 详细讨论了非常类似的例子here

问问,如果您在实施方面遇到困难。

相关问题