Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

Exit Out of Blazor Submit Function based on Timer or Other Click Event

$
0
0

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.


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>