Fix race condition in parallel UI status updates

Prevents stale, intermediate status messages from overwriting the final status of a completed task in the UI.

A set of completed task identifiers is now maintained. Any incoming intermediate status updates for tasks that are already marked as complete are ignored.

The job completion logic is also refactored for better robustness and clarity across different job-end states (failed, completed with data, completed without data).
This commit is contained in:
rbalsleyMSFT
2025-07-17 18:24:44 -07:00
parent b04a8460b0
commit da299d8a03
3 changed files with 77 additions and 64 deletions
@@ -113,7 +113,16 @@ function Update-ListViewItemStatus {
if ($WindowObject -is [System.Windows.Window] -and $ListView -is [System.Windows.Controls.ListView]) {
# Directly update UI elements as this function is now called on the UI thread
try {
$itemToUpdate = $ListView.ItemsSource | Where-Object { $_.$IdentifierProperty -eq $IdentifierValue } | Select-Object -First 1
# Determine which collection to search: ItemsSource (preferred) or Items.
$collectionToSearch = $null
if ($null -ne $ListView.ItemsSource) {
$collectionToSearch = $ListView.ItemsSource
}
else {
$collectionToSearch = $ListView.Items
}
$itemToUpdate = $collectionToSearch | Where-Object { $_.$IdentifierProperty -eq $IdentifierValue } | Select-Object -First 1
if ($null -ne $itemToUpdate) {
$itemToUpdate.$StatusProperty = $StatusValue
$ListView.Items.Refresh() # Refresh the view to show the change