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

Fix: Fixed ArgumentOutOfRangeException in ItemViewModel #14634

Merged
merged 3 commits into from Feb 4, 2024

Conversation

hishitetsu
Copy link
Member

BeginBulkOperation suppresses CollectionChanged and allows changing the collection in non-UI threads. But changing the collection still needs to be done in UI threads, because changes in non-UI threads may not be seen from UI threads soon due to the memory cache.
This PR puts all FilesAndFolders operations into UI threads. This may affect UI performance, but ArgumentOutOfRangeException should no longer be thrown.

Resolved / Related Issues

  • Were these changes approved in an issue or discussion with the project maintainers? In order to prevent extra work, feature requests and changes to the codebase must be approved before the pull request will be reviewed. This prevents extra work for the contributors and maintainers.
    Closes Bug: Adding a file to an open Files directory causes a crash #14169

Validation
How did you test these changes?

  • Did you build the app and test your changes?
  • Did you check for accessibility? You can use Accessibility Insights for this.
  • Did you remove any strings from the en-us resource file?
    • Did you search the solution to see if the string is still being used?
  • Did you implement any design changes to an existing feature?
    • Was this change approved?
  • Are there any other steps that were used to validate these changes?

@hishitetsu hishitetsu changed the title Update ItemViewModel.cs Fix: Fixed ArgumentOutOfRangeException in ItemViewModel Feb 3, 2024
@hez2010
Copy link
Member

hez2010 commented Feb 3, 2024

But changing the collection still needs to be done in UI threads

I think only signaling the event is necessary to happen on UI threads.

@hishitetsu
Copy link
Member Author

I think only signaling the event is necessary to happen on UI threads.

I thought so, too. But I found that putting a breakpoint between the collection change in the non-UI thread and the triggering of the event in the UI thread prevents the exception that could have occurred without the breakpoint. This implies that collection changes are not synchronized between threads. In fact, this PR prevents exceptions. I guess ObservableCollection doesn't assume that collection changes and event triggering take place in different threads.

Comment on lines +704 to +705
FilesAndFolders.Clear();
FilesAndFolders.AddRange(filesAndFoldersLocal);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this time there is no problem and this simplifies the process.

@yaira2 yaira2 added the ready to merge Pull requests that are approved and ready to merge label Feb 4, 2024
@yaira2 yaira2 merged commit f64c971 into files-community:main Feb 4, 2024
6 checks passed
@hishitetsu hishitetsu deleted the UseUIThreads branch February 4, 2024 11:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready to merge Pull requests that are approved and ready to merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: Adding a file to an open Files directory causes a crash
3 participants