[WIP] Add async/await versions for DISM API long-running methods#1
Closed
Copilot wants to merge 1 commit into
Closed
[WIP] Add async/await versions for DISM API long-running methods#1Copilot wants to merge 1 commit into
Copilot wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
AddPackageAsyncto DismApi.AddPackage.csAddCapabilityAsyncto DismApi.AddCapability.csCheckImageHealthAsyncto DismApi.CheckImageHealth.csCommitImageAsyncto DismApi.CommitImage.csDisableFeatureAsyncto DismApi.DisableFeature.csEnableFeatureAsync,EnableFeatureByPackageNameAsync,EnableFeatureByPackagePathAsyncto DismApi.EnableFeature.csMountImageAsync(by index and by name) to DismApi.MountImage.csRemoveCapabilityAsyncto DismApi.RemoveCapability.csRemovePackageByNameAsync,RemovePackageByPathAsyncto DismApi.RemovePackage.csRestoreImageHealthAsyncto DismApi.RestoreImageHealth.csUnmountImageAsyncto DismApi.UnmountImage.csOriginal prompt
Summary
Add async/await versions of all long-running DISM API methods that currently accept a
DismProgressCallback. This addresses Issue #82 in the upstream repo (jeffkl/ManagedDism), which is labeledhelp wantedandenhancement.Background
The current API is entirely synchronous. Every long-running method (e.g.
AddPackage,EnableFeature,MountImage, etc.) blocks the calling thread while the native DISM operation runs. This causes UI freezes in WPF/WinForms/MAUI apps.Current Pattern (example:
AddPackage)Key classes involved:
DismProgress(insrc/Microsoft.Dism/DismProgress.cs) — wraps the native callback, hasCancelproperty that signals anEventWaitHandle, hasCurrent/Total/UserDatapropertiesDismProgressCallback(insrc/Microsoft.Dism/DismProgressCallback.cs) — public delegate:public delegate void DismProgressCallback(DismProgress progress);internal delegate void DismProgressCallback(UInt32 current, UInt32 total, IntPtr userData);Requirements
1. Add
*Asyncmethods to all DismApi partial classes that have long-running operationsFor each method that currently accepts a
DismProgressCallback, add an async counterpart. The async methods should:MethodNameAsyncnaming conventionIProgress<DismProgress>?instead ofDismProgressCallback?for progress reporting (standard .NET pattern)CancellationTokenfor cancellation (standard .NET pattern)Task(since the sync methods return void)Task.Runto offload the blocking native P/Invoke call to a thread pool threadCancellationTokencancellation toDismProgress.Cancel = true(which signals the nativeEventWaitHandle)OperationCanceledExceptionwhen cancelled2. Example of what an async method should look like
3. Methods that need async versions
Look through ALL
DismApi.*.csfiles insrc/Microsoft.Dism/and add async versions for every public method that has aDismProgressCallbackparameter. These include but are not limited to:AddPackage→AddPackageAsyncAddDriver→AddDriverAsyncApplyUnattend→ApplyUnattendAsync(if it has progress)CheckImageHealth→CheckImageHealthAsyncCleanupMountpoints→CleanupMountpointsAsync(if it has progress)CommitImage→CommitImageAsyncDisableFeature→DisableFeatureAsyncEnableFeature/EnableFeatureByPackageName/EnableFeatureByPackagePath→ async versionsMountImage→MountImageAsyncRemountImage→RemountImageAsync(if it has progress)RemovePackage/RemovePackageByName/RemovePackageByPath→ async versionsRestoreImageHealth→RestoreImageHealthAsyncThis pull request was created from Copilot chat.
⚡ Quickly spin up Copilot coding agent tasks from anywhere on your macOS or Windows machine with Raycast.