Skip to content

Commit

Permalink
Merge pull request #3276 from AmrAlSayed0/minWaitTime
Browse files Browse the repository at this point in the history
Avoid waiting more than necessary between navigations
  • Loading branch information
dansiegel authored Dec 15, 2024
2 parents 0ea820c + 4360f17 commit 70b2560
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Maui/Prism.Maui/Navigation/PageNavigationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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/";
Expand Down Expand Up @@ -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 - timeSinceLastNav);
}
}

Expand Down

0 comments on commit 70b2560

Please sign in to comment.