From 10cc574acb15f58fc78ddb79cb93cdead03da1f5 Mon Sep 17 00:00:00 2001 From: MaddoScientisto Date: Sun, 15 Feb 2026 11:14:19 +0100 Subject: [PATCH] Add WPF UI alongside WinForms; improve cancellation logic Introduced MainWindow.xaml and code-behind for a modern WPF interface with tabbed settings. Enabled WPF in project file. Refactored startup to launch WPF or WinForms UI based on availability. Registered WPF MainWindow in DI. Improved DataModel cancellation to be synchronous and log exceptions. Minor logging and comment updates. App now supports both WPF and WinForms frontends. --- imagecatalog/DataModel.cs | 17 +- imagecatalog/ImageCatalog 2.csproj | 1 + imagecatalog/MainWindow.xaml | 244 +++++++++++++++++++++++++++++ imagecatalog/MainWindow.xaml.cs | 193 +++++++++++++++++++++++ imagecatalog/Program.cs | 35 ++++- 5 files changed, 482 insertions(+), 8 deletions(-) create mode 100644 imagecatalog/MainWindow.xaml create mode 100644 imagecatalog/MainWindow.xaml.cs diff --git a/imagecatalog/DataModel.cs b/imagecatalog/DataModel.cs index 6d90981..8091907 100644 --- a/imagecatalog/DataModel.cs +++ b/imagecatalog/DataModel.cs @@ -1132,13 +1132,26 @@ namespace ImageCatalog_2 { try { - await MainToken?.CancelAsync(); + var tokenSource = MainToken; + if (tokenSource is not null) + { + // Cancel synchronously and return to caller. Some CTSource implementations + // may provide async helpers but cancelling is immediate. + try + { + tokenSource.Cancel(); + } + catch (Exception ex) + { + _logger.LogWarning(ex, "Exception while cancelling token"); + } + } UiEnabled = true; } catch (Exception e) { - _logger.LogError(e.Message, "Error canceling the token"); + _logger.LogError(e, "Error canceling the token"); _logger.LogInformation("Ignora questo errore"); } } diff --git a/imagecatalog/ImageCatalog 2.csproj b/imagecatalog/ImageCatalog 2.csproj index e0acb4f..4563b31 100644 --- a/imagecatalog/ImageCatalog 2.csproj +++ b/imagecatalog/ImageCatalog 2.csproj @@ -5,6 +5,7 @@ enable enable true + true False 3.1.2.0 3.1.2.0 diff --git a/imagecatalog/MainWindow.xaml b/imagecatalog/MainWindow.xaml new file mode 100644 index 0000000..b2bd652 --- /dev/null +++ b/imagecatalog/MainWindow.xaml @@ -0,0 +1,244 @@ + + + + + + + + + + + + + + + + + + + + + + + + + +