From bf0d0ffa1ddd678dba63924f75328cd7d3e4820d Mon Sep 17 00:00:00 2001 From: Copilot <223556219+Copilot@users.noreply.github.com> Date: Tue, 14 Apr 2026 11:13:30 +0800 Subject: [PATCH] Auto-load model and run inference on WinUI app launch Instead of requiring the user to manually select an EP and click 'Load / Reload Model', the app now automatically loads the model with the default execution provider and runs inference on startup. If auto-load fails (e.g. no GPU for DML), the error is shown and the user can still manually select a different EP and retry. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- Samples/WindowsML/cs-winui/MainWindow.xaml.cs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/Samples/WindowsML/cs-winui/MainWindow.xaml.cs b/Samples/WindowsML/cs-winui/MainWindow.xaml.cs index d3abb598e..75d8b6c1b 100644 --- a/Samples/WindowsML/cs-winui/MainWindow.xaml.cs +++ b/Samples/WindowsML/cs-winui/MainWindow.xaml.cs @@ -78,8 +78,24 @@ private async Task InitializeAndRunDemoAsync() EpCombo.SelectionChanged += EpCombo_SelectionChanged; providerInfo.AppendLine("========================================"); - providerInfo.AppendLine("Select an execution provider (and device if required) then click 'Load / Reload Model'."); + providerInfo.AppendLine("Auto-loading model with default execution provider..."); ResultsText.Text = providerInfo.ToString(); + + // Auto-load model and run inference on startup + try + { + await LoadModelAsync(); + if (_session != null) + { + await LoadAndRunDemoAsync(); + } + } + catch (Exception ex) + { + ResultsText.Text = providerInfo.ToString() + + $"\nAuto-load failed: {ex.Message}" + + "\nSelect an execution provider and click 'Load / Reload Model' to retry."; + } } catch (Exception ex) {