Intento crear un tiempo de espera de sesión en una aplicación de servidor Blazor. La ventana emergente se crea en la función JS con un valor de promesa de devolución. Devuelva "Y" por defecto cuando el temporizador se acabe o se haga clic en el botón de confirmación; de lo contrario, devolverá "N".
Sin embargo, el valor devuelto siempre es "Y", independientemente de que se haga clic en CancelButton. El valor de rslt a continuación es siempre "Y". ¿Alguien puede ayudar a señalar lo que me perdí aquí? ¡Gracias!
string rslt = await _jsRuntime.InvokeAsync<string>("timeOutBox", "Session Alert", "Your session will be closed in <b></b> seconds.", 30000, "warning", "Logout", "Stay connected" ); await Task.Delay(500); if ( rslt=="Y" ) //confirm logout click or timer ran out { CleanUp(); // remove local storage and tracking list _navi.NavigateTo("/", true); // force to login page } else { // Reset timer // Identify whether the user is active or inactive using onmousemove and onkeypress in JS function. timerStarted = false; await _jsRuntime.InvokeVoidAsync("timeOutCall", DotNetObjectReference.Create(this)); } <pre> function timeOutBox(title, html, timer, icon, logouttext, staytext) { return new Promise(resolve => { let timerInterval let ans ="Y" Swal.fire({ title: title, html: html, timer: timer, icon: icon, showConfirmButton: true, showCancelButton: true, confirmButtonText: logouttext, cancelButtonText: staytext, timerProgressBar: true, didOpen: () => { //Swal.showLoading() //if show loading spinner, it will overide buttons const b = Swal.getHtmlContainer().querySelector('b') timerInterval = setInterval(() => { b.textContent = Swal.getTimerLeft() }, 1000) }, willClose: () => { clearInterval(timerInterval) // will return resolve ="Y" // force logout return resolve(ans); } }).then((result) => { if (result.isConfirmed) { // confirm logout return resolve(ans); } else { ans = "N"; return resolve(ans); } }) }) </pre>