{
var a = GridData.First();
a.CustomerID = "Update";
}to public async Task UpdateRecords()
{
for (int i = 0; i < 10; i++)
{
var a = GridData.First();
a.CustomerID = $"Update No.{i}";
await Task.Delay(1000);
}
}
I notice that the grid only updates the on the first iteration of the loop. Why is this?
|
<button @onclick="StartTimer">Start Update</button>
<button @onclick="StopTimer">Stop Update</button>
<SfGrid DataSource="@GridData" AllowReordering="true">
<GridColumns>
. . . .. . . .
</GridColumns>
</SfGrid>
@code{
private static System.Timers.Timer aTimer;
public void StopTimer()
{
aTimer.Stop();
}
public async Task StartTimer()
{
// Create a timer with a two second interval.
aTimer = new System.Timers.Timer(2000);
// Hook up the Elapsed event for the timer.
aTimer.Elapsed += async (sender, e) => await HandleTimer();
aTimer.Start();
}
private async Task HandleTimer()
{
var a = GridData.First();
a.CustomerID = (new string[] { "ALFKI", "ANANTR", "ANTON", "BLONP", "BOLID" })[new Random().Next(5)];
await InvokeAsync(StateHasChanged);
}
}
|