From e03bc5ca12011055ac87e9d56e322cba1266cb7c Mon Sep 17 00:00:00 2001 From: Amr Date: Wed, 6 Nov 2024 10:19:37 +0200 Subject: [PATCH 1/2] Avoid waiting more than necessary between navigations --- src/Maui/Prism.Maui/Navigation/PageNavigationService.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Maui/Prism.Maui/Navigation/PageNavigationService.cs b/src/Maui/Prism.Maui/Navigation/PageNavigationService.cs index f9ea5160b..b26d11d89 100644 --- a/src/Maui/Prism.Maui/Navigation/PageNavigationService.cs +++ b/src/Maui/Prism.Maui/Navigation/PageNavigationService.cs @@ -14,6 +14,7 @@ namespace Prism.Navigation; public class PageNavigationService : INavigationService, IRegistryAware { private static readonly SemaphoreSlim _semaphore = new (1, 1); + private static readonly TimeSpan _minTimeBetweenNavigations = TimeSpan.FromMilliseconds(150); private static DateTime _lastNavigate; internal const string RemovePageRelativePath = "../"; internal const string RemovePageInstruction = "__RemovePage/"; @@ -414,9 +415,10 @@ private static async Task WaitForPendingNavigationRequests() { await _semaphore.WaitAsync(); // Ensure adequate time has passed since last navigation so that UI Refresh can Occur - if (DateTime.Now - _lastNavigate < TimeSpan.FromMilliseconds(150)) + TimeSpan timeSinceLastNav = DateTime.Now - _lastNavigate; + if (timeSinceLastNav < _minTimeBetweenNavigations) { - await Task.Delay(150); + await Task.Delay(_minTimeBetweenNavigations - timePassedSinceLastNav); } } From 4360f17eb4ffc92c1f326cecfbb20d901d5b4345 Mon Sep 17 00:00:00 2001 From: Amr Date: Wed, 6 Nov 2024 10:30:20 +0200 Subject: [PATCH 2/2] Miss-named variable --- src/Maui/Prism.Maui/Navigation/PageNavigationService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Maui/Prism.Maui/Navigation/PageNavigationService.cs b/src/Maui/Prism.Maui/Navigation/PageNavigationService.cs index b26d11d89..0888a3f0d 100644 --- a/src/Maui/Prism.Maui/Navigation/PageNavigationService.cs +++ b/src/Maui/Prism.Maui/Navigation/PageNavigationService.cs @@ -418,7 +418,7 @@ private static async Task WaitForPendingNavigationRequests() TimeSpan timeSinceLastNav = DateTime.Now - _lastNavigate; if (timeSinceLastNav < _minTimeBetweenNavigations) { - await Task.Delay(_minTimeBetweenNavigations - timePassedSinceLastNav); + await Task.Delay(_minTimeBetweenNavigations - timeSinceLastNav); } }