mirror of
https://github.com/rbalsleyMSFT/FFU.git
synced 2026-06-14 02:09:35 -06:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user