How do I cancel or timeout navigation?

Platform: .NET MAUI| Category: Navigation

GoToAsync has no built-in CancellationToken. You can time out your await with Task.WaitAsync (recent .NET), but that cancels only your wait; it does not abort the underlying navigation unless that code observes cancellation. For true cancellation, make your page/ViewModel operations cancellation-aware.

Time-out example:

using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(5)); 

try 

{ 

    await Shell.Current.GoToAsync("route").WaitAsync(cts.Token); 

} 

catch (OperationCanceledException) { /* timeout handling */ }

Share with

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.