moxmlb
moxmlb

Reputation: 1330

How to show a progress in a TextBlock and ProgressBar?

i want to show the progress of my Excel reading programm. Here some code:

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";
    }
}

The ProgressBar Maximum is the number of rows in an excel file. After each loop, the TextBlock should show, that the name was created. The ProgressBar value should show the progress.

My window looks like this: Window with a Textblock at the top and a ProgressBar at the bottom

But the Window shows only the end of the excel reading. It dont refresh the TextBlock or the ProgressBar. I only see the empty window and at the end this window: End of Progress

Can someone help me? Thx

Upvotes: 2

Views: 78

Answers (1)

Fragment
Fragment

Reputation: 1585

You should use backgroundWorker to achieve this. Very similiar example is discussed in detail here

Ask, if you'll have difficulties with implementation.

Upvotes: 1

Related Questions