Skip to content
Open
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
18 changes: 17 additions & 1 deletion Samples/WindowsML/cs-winui/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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...");
Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

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

The status text says "default execution provider", but the code path uses whatever EP is currently selected in EpCombo (which is set to the first EP name after sorting in PopulateEpCombo). This may not be the actual/default EP and can mislead users. Consider changing the message to reflect the actual selected EP (e.g., include EpCombo.SelectedItem) or use wording like "Auto-loading model with selected execution provider".

Suggested change
providerInfo.AppendLine("Auto-loading model with default execution provider...");
var selectedExecutionProvider = EpCombo.SelectedItem?.ToString();
providerInfo.AppendLine(
string.IsNullOrWhiteSpace(selectedExecutionProvider)
? "Auto-loading model with selected execution provider..."
: $"Auto-loading model with selected execution provider: {selectedExecutionProvider}...");

Copilot uses AI. Check for mistakes.
ResultsText.Text = providerInfo.ToString();

// Auto-load model and run inference on startup
try
{
await LoadModelAsync();
if (_session != null)
Comment on lines +84 to +88
Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

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

Auto-load now calls LoadModelAsync() immediately after InitializeAndRunDemoAsync() already initialized providers. Since LoadModelAsync() calls ModelManager.InitializeExecutionProvidersAsync(...) again, startup will run provider initialization twice (including EnsureReadyAsync/registration loops), which can add noticeable launch latency. Consider making provider initialization idempotent/cached (e.g., track a "providers initialized" flag) or remove the redundant initialization call from one of the paths.

Copilot uses AI. Check for mistakes.
{
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.";
Comment on lines +95 to +97
Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

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

This builds providerInfo with StringBuilder.AppendLine() (which uses Windows newlines) but then appends additional lines using hard-coded "\n". Mixing newline conventions can lead to inconsistent rendering in the UI. Prefer using Environment.NewLine consistently, or append these lines to the same StringBuilder via AppendLine() before assigning to ResultsText.Text.

Suggested change
ResultsText.Text = providerInfo.ToString()
+ $"\nAuto-load failed: {ex.Message}"
+ "\nSelect an execution provider and click 'Load / Reload Model' to retry.";
var failureInfo = new StringBuilder(providerInfo.ToString());
failureInfo.AppendLine($"Auto-load failed: {ex.Message}");
failureInfo.AppendLine("Select an execution provider and click 'Load / Reload Model' to retry.");
ResultsText.Text = failureInfo.ToString();

Copilot uses AI. Check for mistakes.
}
}
catch (Exception ex)
{
Expand Down
Loading