C
C#16mo ago
BlackNet

❔ Problem updating ui component in razor page using blazor app

anyone got experience in hosting a blazor server app in docker container? i am having an issue, i can't seems to update ui component on the blazor page, i am using a disposable timer and it gets immediately disposed after loading the page
2 Replies
BlackNet
BlackNetOP16mo ago
<table class="table">
<thead>
<tr>
<th>Name</th>
<th>Encoded (seconds)</th>
<th>Total (seconds)</th>
</tr>
</thead>
<tbody>
@foreach (var progress in ProgressRecords)
{
<tr>
<td>@progress.Name</td>
<td>@progress.Encoded</td>
<td>@progress.Total</td>
</tr>
}
</tbody>
</table>
<table class="table">
<thead>
<tr>
<th>Name</th>
<th>Encoded (seconds)</th>
<th>Total (seconds)</th>
</tr>
</thead>
<tbody>
@foreach (var progress in ProgressRecords)
{
<tr>
<td>@progress.Name</td>
<td>@progress.Encoded</td>
<td>@progress.Total</td>
</tr>
}
</tbody>
</table>
private List<ProgressRecord>? ProgressRecords { get; set; }
private class ProgressRecord
{
public string Name;
public int Total;
public int Encoded;
}

PeriodicTimer periodicTimer = new(TimeSpan.FromSeconds(10));

protected override void OnInitialized()
{
UpdateProgress();
RunTimer(); // fire-and-forget
}

async void RunTimer()
{
while (await periodicTimer.WaitForNextTickAsync())
{
await InvokeAsync(() =>
{
UpdateProgress();
StateHasChanged();
});
}
}

public void Dispose()
{
MyLogger.LogError("Disposed");
periodicTimer?.Dispose();
}
private void UpdateProgress()
{
ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("redis");
ProgressRecords = new List<ProgressRecord>();

IDatabase db = redis.GetDatabase();
var endpoints = redis.GetEndPoints();
var s = redis.GetServer(endpoints[0]);
var keys = s.Keys(pattern: "*").ToArray();

foreach (var key in keys)
{
MyLogger.LogInfo($"Data found! {key}");
var hashFields = db.HashGetAll(key);
var encoded = (int)hashFields[0].Value;
var total = (int)hashFields[1].Value;
ProgressRecords.Add(new ProgressRecord { Name = key, Total = total, Encoded = encoded });
}
}
private List<ProgressRecord>? ProgressRecords { get; set; }
private class ProgressRecord
{
public string Name;
public int Total;
public int Encoded;
}

PeriodicTimer periodicTimer = new(TimeSpan.FromSeconds(10));

protected override void OnInitialized()
{
UpdateProgress();
RunTimer(); // fire-and-forget
}

async void RunTimer()
{
while (await periodicTimer.WaitForNextTickAsync())
{
await InvokeAsync(() =>
{
UpdateProgress();
StateHasChanged();
});
}
}

public void Dispose()
{
MyLogger.LogError("Disposed");
periodicTimer?.Dispose();
}
private void UpdateProgress()
{
ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("redis");
ProgressRecords = new List<ProgressRecord>();

IDatabase db = redis.GetDatabase();
var endpoints = redis.GetEndPoints();
var s = redis.GetServer(endpoints[0]);
var keys = s.Keys(pattern: "*").ToArray();

foreach (var key in keys)
{
MyLogger.LogInfo($"Data found! {key}");
var hashFields = db.HashGetAll(key);
var encoded = (int)hashFields[0].Value;
var total = (int)hashFields[1].Value;
ProgressRecords.Add(new ProgressRecord { Name = key, Total = total, Encoded = encoded });
}
}
the timer gets disposed immediately after loading the page, doesn't even tick once figured out this stupid issue it just doesn't work in .net 8 reverted to .net 7 and it works as it should
Accord
Accord16mo ago
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server