Updating value for progress bar

Hello!
The progress bar does not update its state during execution until the process is completed:
[Parameter]
public double progress { get; set; } = 0;
public void StartProgress(int steps)
{
for (int i = 1; i <= steps; i++)
{
progress = i * 100 / steps;
Console.WriteLine(progress);
Thread.Sleep(1000);
}
}
The value property binding with ${progress}
Output console returns correct values 1-100
I ask for help with advice, how to update the value for the progress bar dynamically?

Your code blocks the thread until it ends. Blazor cannot update in such case.

You should probably make it async in some way and call StateHasChanged(). This may give Blazor a chance to update.

Found this which could help: https://stackoverflow.com/questions/55455428/what-is-the-recommended-way-to-release-the-ui-from-a-long-running-background-tas

1 Like