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:
@@ -234,7 +234,7 @@ function Invoke-CopyBYOApps {
|
||||
|
||||
$allAppsWithSource = $State.Controls.lstApplications.Items | Where-Object { -not [string]::IsNullOrWhiteSpace($_.Source) }
|
||||
if (-not $allAppsWithSource) {
|
||||
[System.Windows.MessageBox]::Show("UserAppList.json has been updated. No applications with a source path were found to copy.", "Copy BYO Apps", "OK", "Information")
|
||||
[System.Windows.MessageBox]::Show("No applications with a source path were found to copy.", "Copy BYO Apps", "OK", "Information")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -341,7 +341,7 @@ function Start-CopyBYOApplicationTask {
|
||||
}
|
||||
|
||||
if (-not (Test-Path -Path $sourcePath -PathType Container)) {
|
||||
$status = "Error: Source path not found"
|
||||
$status = "Source path not found"
|
||||
Invoke-ProgressUpdate -ProgressQueue $ProgressQueue -Identifier $appName -Status $status
|
||||
WriteLog "Copy error for $($appName): Source path '$sourcePath' not found."
|
||||
return [PSCustomObject]@{ Name = $appName; Status = $status; Success = $success }
|
||||
@@ -381,12 +381,7 @@ function Start-CopyBYOApplicationTask {
|
||||
# Enqueue error status
|
||||
Invoke-ProgressUpdate -ProgressQueue $ProgressQueue -Identifier $appName -Status $status
|
||||
}
|
||||
|
||||
# Enqueue final success status if applicable
|
||||
if ($success) {
|
||||
Invoke-ProgressUpdate -ProgressQueue $ProgressQueue -Identifier $appName -Status $status
|
||||
}
|
||||
|
||||
|
||||
# Return the final status
|
||||
return [PSCustomObject]@{ Name = $appName; Status = $status; Success = $success }
|
||||
}
|
||||
|
||||
@@ -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