Blazor Server .NET 8.
What I want to achieve is that when a user clicks on a button, it calls a function that begins a process. I want the user to then click a different button that could stop that process before time runs out. However, my implementations block the UI for some reason.
<RadzenButton Size="ButtonSize.Medium" ButtonStyle="ButtonStyle.Primary" ButtonType="ButtonType.Submit" Text="Send" Icon="send" Click=@HandleValidSubmitAsync /><RadzenButton Click=@Cancel Text="Cancel" ButtonStyle="ButtonStyle.Light" />code behind:
bool _cancelled { get; set; }async void HandleValidSubmitAsync(){ Stopwatch s = new Stopwatch(); s.Start(); while (s.Elapsed < TimeSpan.FromSeconds(valFromAppSettings)) { if (_cancelled ) return; } s.Stop(); if (!_cancelled) { // do work }}void Cancel(){ _cancelled = true; StateHasChanged();}So after I click the button for HandleValidSubmitAsync and the timer starts, then I click Cancel, the Cancel button never hits the Cancel function, and therefore that while loop will never return out.
I hope this makes sense.