From 40fe9369f5d652988ab28febd04ba23f3ebdb766 Mon Sep 17 00:00:00 2001 From: Matheos Mattsson Date: Wed, 9 Jul 2025 15:33:59 +0300 Subject: [PATCH 1/2] Massive refactor to support sequential loading while keeping the UI usable. Each file and thumbnail is loaded into memory, one by one, on a separate thread. The UI is updated from the other thread when needed. This is not superfast but the user is meant to start working from the top, while it loads, and it is fast enough for it to not be a bottleneck in usage (hopefully lol) --- FileItem.cs | 21 +--- MainWindow.axaml | 11 +- MainWindow.axaml.cs | 246 ++++++++++++++++++++++++++------------------ 3 files changed, 155 insertions(+), 123 deletions(-) diff --git a/FileItem.cs b/FileItem.cs index 3662f68..4f19c89 100644 --- a/FileItem.cs +++ b/FileItem.cs @@ -8,12 +8,11 @@ namespace SelectSight; using System.Threading.Tasks; using Avalonia.Media.Imaging; -public class FileItem : INotifyPropertyChanged +public class FileItem(string fullPath) : INotifyPropertyChanged { - public string FullPath { get; } - public string Name { get; } - public string SizeString { get; } - + public string FullPath { get; } = fullPath; + public string Name { get; } = Path.GetFileName(fullPath); + private Bitmap? _thumbnail; public Bitmap? Thumbnail { @@ -21,17 +20,7 @@ public Bitmap? Thumbnail private set => SetField(ref _thumbnail, value); } - public FileItem(string fullPath) - { - FullPath = fullPath; - Name = Path.GetFileName(fullPath); - SizeString = new FileInfo(fullPath).Length.ToString("N0") + " bytes"; - - // Start loading thumbnail asynchronously - _ = LoadThumbnailAsync(); - } - - private async Task LoadThumbnailAsync() + public async Task LoadThumbnailAsync() { try { diff --git a/MainWindow.axaml b/MainWindow.axaml index 6f695d4..0dab3ec 100644 --- a/MainWindow.axaml +++ b/MainWindow.axaml @@ -9,12 +9,13 @@ Icon="avares://SelectSight/Assets/icon.ico"> - + @@ -73,7 +74,7 @@ Background="Transparent" Padding="10"> - + @@ -93,7 +94,7 @@