Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid waiting more than necessary between navigations #3276

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading