Suggestion: Async/Await implementation.
Hello Can you add an async version of DISM api. For example with EnableFeatureByPackageNameAsync:
public static Task<bool> EnableFeatureByPackageNameAsync(DismSession session, string featureName, string packageName, bool limitAccess, bool enableAll, List<string> sourcePaths, CancellationToken token, IProgress<DismProgressAsync> progress);
With DismProgressAsync is the same as DismProgress without cancellation
If the task result is bool==true reboot are required.
with that the library customer can do:
class MyprogressReporter : iProgress<DismProgressAsync>
{
public void Report (DismProgressAsync value)
{
// update the UI
}
...
}
...
var progress=new MyprogressReporter();
CancellationTokenSource source = new CancellationTokenSource();
var tsk = EnableFeatureByPackageNameAsync(session, "myfeature", string.Empty, false, true, new List<string>(), source.Token, progress);
//if the user want to cancel
source.Cancel()
//Or after a delay
source.CancelAfter(delay);
// Or wait for the result
bool rebootRequired = await tsk;
It's easily implementable with TaskCompletionSource<TResult>. I hope I did not make any mistakes. Thank you for your library.
This sounds interesting. Does wrapping the call in a Task.Run() give you the same result? I'd be happy to accept any contributions that add async functionality if you have time.
@mveril I understand the nature of your request, but I don't believe this is appropriate as it is not "async all the way down." That is, the DISM API is not truly asynchronous, and so providing asynchronous APIs to wrap it (via this library) isn't faithful.
I would instead encourage you to wrap calls in Task.Run() as @jeffkl mentioned; you could, as you mentioned, set it up to return a Task
Task<bool> t = Task.Run(() => { return EnableFeatureByPackageName(); })