Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion: Async/Await implementation. #82

Open
mveril opened this issue Dec 8, 2019 · 2 comments
Open

Suggestion: Async/Await implementation. #82

mveril opened this issue Dec 8, 2019 · 2 comments

Comments

@mveril
Copy link

mveril commented Dec 8, 2019

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.
I hope I did not make any mistakes.
Thank you for your library.

@jeffkl
Copy link
Owner

jeffkl commented Dec 9, 2019

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.

@Shidell
Copy link
Contributor

Shidell commented Dec 10, 2019

@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, for example:

Task<bool> t = Task.Run(() => { return EnableFeatureByPackageName(); })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants