Sorry in advance for any lack of clarity with my issue.
My Blazor MAUI app entails components which have their own counting thread. They start and stop just fine except when I leave the page and return to it ( https://gifyu.com/image/S58Nw ).
private async void RT_ToggleActiveEndpoint(EndPointModel epm)
{
if (!epm.IsActive)
{
epm.IsActive = true;
await Loop();
}
else
{
StopThreadCounter(epm);
}
}
public async Task Loop()
{
if (!EPM.IsActive) return;
while (EPM.IsActive)
{
EPM.counter++;
StateHasChanged();
await Task.Delay(1000);
}
}
private void StartThreadCounter(EndPointModel epm)
{
epm.IsActive = true;
}
private void StopThreadCounter(EndPointModel epm)
{
epm.IsActive = false;
epm.counter = 0;
}
The thread continues running in the background but stops updating the UI when page navigation is changed. The code above is a component of the main page. I realize the code shown uses Task and not thread however, the result is the same regardless.