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
@@ -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 }
}