Skip to content

Refactor: Add IsDisposed property to IShellPage and check before updating #17320

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions src/Files.App/Data/Contexts/ContentPage/ContentPageContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@ private void FilesystemViewModel_PropertyChanged(object? sender, PropertyChanged

private void Update()
{
if (ShellPage is null || ShellPage.IsDisposed)
return;

UpdatePageType();
UpdateSelectedItems();

Expand Down
5 changes: 5 additions & 0 deletions src/Files.App/Data/Contracts/IShellPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ public interface IShellPage : ITabBarItemContent, IMultiPaneInfo, IDisposable, I

StorageHistoryHelpers StorageHistoryHelpers { get; }

/// <summary>
/// Gets a value indicating whether this instance is disposed.
/// </summary>
bool IsDisposed { get; }

IList<PageStackEntry> ForwardStack { get; }

IList<PageStackEntry> BackwardStack { get; }
Expand Down
4 changes: 4 additions & 0 deletions src/Files.App/Views/Shells/BaseShellPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public abstract class BaseShellPage : Page, IShellPage, INotifyPropertyChanged
{
private readonly DispatcherQueueTimer _updateDateDisplayTimer;

public bool IsDisposed { get; private set; } = false;

private DateTimeFormats _lastDateTimeFormats;

private Task _gitFetch = Task.CompletedTask;
Expand Down Expand Up @@ -764,6 +766,8 @@ private void UpdateDateDisplayTimer_Tick(object sender, object e)

public virtual void Dispose()
{
IsDisposed = true;

PreviewKeyDown -= ShellPage_PreviewKeyDown;
PointerPressed -= CoreWindow_PointerPressed;
drivesViewModel.PropertyChanged -= DrivesManager_PropertyChanged;
Expand Down
Loading