WPF progress bar update without dispatcher
I am trying to show a progress bar on seperate window on a button click. I dont want to use dispatcher,invoke function because I dont want user to do anything else until it completes.
So on button click im calling a function which is internally using delegate to call the function with the update.
void button click()
{
classA.function(list);
}
Inside that classA
void function(list)
{
foreach(list)
calling the delegate function(ShowtProgress) to update the progress bar with current and max properties.
}
so my delegate function looks something like this:
private void ShowtProgress(ProgressReport importProgressReport)
{
importProgressBar.UpdateProgressBar(importProgressReport.OverallProgress.TotalItems,importProgressReport.OverallProgress.开发者_运维问答ItemsProcessed);
importProgressBar.ShowDialog();
}
As you can see that im passing how many are currently processed and total items to the progress bar updateProgressbar function to update the progress bar.
I have defined progress bar's minimum to 0.
But the problem is the moment it shows the showdialog(of progress bar) the first time when min = 0 and assume max = 1. it stays right there waiting for the user's input. Until I dont close the dialog the processing doesn't go further and when again this function is called the modal doesn't pop up or doesn't get updated with the latest value.
Do let me know, if I have missed anything.
It is waiting for user input because of the ShowDialog()
call. Use either the normal Show()
(if importProgressBar
wasn't visible) or just remove the line if it was already.
精彩评论