I am currently working on a Blazor project and facing with a bug. The plan is to update a component in every second, as long as the for loop updates. My problem is a bit complex, so I reproduced this bug in another project:
The Calculate.cs file where the calculations happen:
public class Calculate
{
public void Calc(Index index)
{
for (int i = 0; i < 10; i++)
{
Thread.Sleep(1000);
index.Update(i);
}
}
}
The index.razor file:
<button class="btn btn-primary" @onclick="Test">Click me</button>
<p>Test number: @testNumber</p>
@code
{
private int testNumber;
Calculate c = new Calculate();
public void Test()
{
c.Calc(this);
}
public void Update(int i)
{
testNumber = i;
Debug.WriteLine(i);
}
}
After testing, the Debug Console prints the numbers as it should in every second, all the way from 0-9, but the opened Blazor display only prints the 9, whenever the calculations and the 10 seconds are over.