@page "/myorders/{orderId:int}" @attribute [Authorize] @using System.Threading @inject OrdersClient OrdersClient @implements IDisposable
@if (invalidOrder) {

NEIN

Konnte keine Bestellungen laden

} else if (orderWithStatus == null) { Lade... } else {

Bestellt am @orderWithStatus.Order.CreatedTime.ToLongDateString()

Status: @orderWithStatus.StatusText

}
@code { [Parameter] public int OrderId { get; set; } OrderWithStatus orderWithStatus; bool invalidOrder; CancellationTokenSource pollingCancellationToken; protected override void OnParametersSet() { // If we were already polling for a different order, stop doing so pollingCancellationToken?.Cancel(); // Start a new poll loop PollForUpdates(); } private async void PollForUpdates() { invalidOrder = false; pollingCancellationToken = new CancellationTokenSource(); while (!pollingCancellationToken.IsCancellationRequested) { try { orderWithStatus = await OrdersClient.GetOrder(OrderId); StateHasChanged(); if (orderWithStatus.IsDelivered) { pollingCancellationToken.Cancel(); } else { await Task.Delay(4000); } } catch (AccessTokenNotAvailableException ex) { pollingCancellationToken.Cancel(); ex.Redirect(); } catch (Exception ex) { invalidOrder = true; pollingCancellationToken.Cancel(); Console.Error.WriteLine(ex); StateHasChanged(); } } } void IDisposable.Dispose() { pollingCancellationToken?.Cancel(); } }