GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add 5 'InvokeAsync' overloads and 'StopAsync' to the 'PowerShell' type by KirkMunro · Pull Request #8056 · PowerShell/PowerShell

Conversation

@KirkMunro

@KirkMunro Kirk Munro (KirkMunro) commented Oct 17, 2018 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

PR Summary

It is much easier to deal with asynchronous invocation of PowerShell using async and await, but the S.M.A.PowerShell class only exposes BeginInvoke and EndInvoke methods for async support. This PR adds 5 InvokeAsync overloads (one for each BeginInvoke method) to S.M.A.PowerShell to facilitate async invocation of PowerShell commands from .NET.

PR Checklist

  • PR has a meaningful title
    • Use the present tense and imperative mood when describing your changes
  • Summarized changes
  • Change is not breaking
  • Make sure all .h, .cpp, .cs, .ps1 and .psm1 files have the correct copyright header
  • This PR is ready to merge and is not Work in Progress.
    • If the PR is work in progress, please add the prefix WIP: to the beginning of the title and remove the prefix when the PR is ready.
  • User-facing changes
    • Not Applicable
    • OR
    • User-facing Documentation needed
      • Issue filed - Issue link: Add S.M.A.PowerShell.InvokeAsync and .StopAsync documentation MicrosoftDocs/PowerShell-Docs#3129
  • Testing - New and feature
    • Not Applicable or can only be tested interactively
    • OR
    • Make sure you've added a new test if existing tests do not effectively test the code changed
      • Add [feature] if the change is significant or affects feature tests

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@KirkMunro
Add 5 InvokeAsync overloads
1158943
@KirkMunro
Kirk Munro (KirkMunro) requested review from Bruce Payette (BrucePay) and Dongbo Wang (daxian-dbw) as code owners October 17, 2018 01:54
@KirkMunro

Kirk Munro (KirkMunro) commented Oct 17, 2018

Copy link
Copy Markdown
Contributor Author

Note that I have not added unit tests yet for this PR. I looked to see where BeginInvoke and EndInvoke were tested, and they are included as part of a Pester test; however, PowerShell does not support async/await, so Pester does not appear to be an appropriate test framework for these changes. Please identify how these new methods should be automatically tested. I haven't added C# unit tests to this repo yet, so I'm not sure how I should proceed. Thank you.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@KirkMunro
CodeFactor changes
ad01380
@iSazonov Ilya (iSazonov) added the Review - Committee The PR/Issue needs a review from the PowerShell Committee label Oct 17, 2018
@iSazonov

Ilya (iSazonov) commented Oct 17, 2018

Copy link
Copy Markdown
Collaborator

Kirk Munro (@KirkMunro) Have you any gists with demo? It would help to document the enhancement.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@KirkMunro

Kirk Munro (KirkMunro) commented Oct 17, 2018

Copy link
Copy Markdown
Contributor Author

I don't have examples showing how complicated this can be using BeginInvoke/EndInvoke, because I just went straight to defining these locally in projects where I have used async PowerShell invocation since they are just so much simpler, so I don't have a before/after example to show for comparison. Also, the code is so short, I'll just share it here instead of in a gist. Here's a snippet showing what use of this looks like when you want async invocation of PowerShell from a .NET assembly with these additional methods in place:

using (var ps = PowerShell.Create())
{
    ps.AddCommand("Connect-AzureRmAccount")
      .AddParameter("ServicePrincipal")
      .AddParameter("TenantId", tenantName)
      .AddParameter("Subscription", subscriptionId)
      .AddParameter("Credential", credential);

    var results = await ps.InvokeAsync();
    // Process results
}
iSazonov reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@adityapatwardhan

Aditya Patwardhan (adityapatwardhan) commented Oct 18, 2018

Copy link
Copy Markdown
Member

Kirk Munro (@KirkMunro) You can add C# tests here: https://github.com/PowerShell/PowerShell/tree/master/test/csharp

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@SteveL-MSFT

Steve Lee (SteveL-MSFT) commented Oct 24, 2018

Copy link
Copy Markdown
Member

@PowerShell/powershell-committee agree that we should expose a task model for async PowerShell, leaving implementation details to PR review

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@SteveL-MSFT Steve Lee (SteveL-MSFT) added Committee-Reviewed PS-Committee has reviewed this and made a decision and removed Review - Committee The PR/Issue needs a review from the PowerShell Committee labels Oct 24, 2018
@daxian-dbw

Dongbo Wang (daxian-dbw) commented Oct 24, 2018

Copy link
Copy Markdown
Member

Bruce Payette (@BrucePay) Can you please review the signature of the proposed task-based async APIs?

In committee's discussion on this, there are proposals that we might want to re-implement the async invocation in the task-based model instead of wrapping the Begin/End Invoke. But as long as the API signatures are reviewed and approved, I guess we can go with wrapping the existing async APIs for now, and replace the implementation of those task-based APIs at later time, if we want to.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@KirkMunro

Kirk Munro (KirkMunro) commented Oct 27, 2018

Copy link
Copy Markdown
Contributor Author

Regarding c# unit tests, I didn't get to them before going on vacation this week, so I'll come back to this PR next week and catch up.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Kirk Munro (KirkMunro) added 4 commits November 4, 2018 15:56
@KirkMunro
Merge branch 'master' into powershell-invokeasync-methods
db1cb6e
@KirkMunro
first crack at some C# unit tests
f7e1f62
@KirkMunro
codefactor -- added header to file
1d32ec6
@KirkMunro
updated PowerShell member count
e42db00
@iSazonov

Ilya (iSazonov) commented Nov 5, 2018

Copy link
Copy Markdown
Collaborator

@powershell-maintainers The test/csharp folder is targeted as Linux-only tests. Suggestion is to put new tests in test/xUnit/System.Management.Automation. Sample https://github.com/iSazonov/PowerShell/tree/add-unicode3/test/xUnit/System.Management.Automation

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@KirkMunro

Kirk Munro (KirkMunro) commented Nov 5, 2018

Copy link
Copy Markdown
Contributor Author

Ilya (@iSazonov) I'll move the tests over. Thanks for letting me know the correct path for those tests.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@KirkMunro

Kirk Munro (KirkMunro) commented Nov 5, 2018

Copy link
Copy Markdown
Contributor Author

Wait. Ilya (@iSazonov), that path doesn't exist in master, so this is a new process then? How are tests under that path executed locally for verification?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@iSazonov

Ilya (iSazonov) commented Nov 5, 2018 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Collaborator

Kirk Munro (@KirkMunro) We haven't such tests at all. And my question is for MSFT team where we should place these tests. I point my new unmerged code which have engine API xUnit tests too. I look how CoreFX places API tests and do the same.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@KirkMunro

Kirk Munro (KirkMunro) commented Nov 5, 2018

Copy link
Copy Markdown
Contributor Author

Ilya (@iSazonov) Ok, thanks. I'll wait until the other maintainers discuss with you what should be done with these then, and follow the process accordingly.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@KirkMunro Kirk Munro (KirkMunro) mentioned this pull request Nov 5, 2018
Make S.M.A.PowerShell.GetSteppablePipeline method public #8055
Merged
7 of 11 tasks
@KirkMunro
Merge branch 'master' into powershell-invokeasync-methods
eee1a07
@stale

stale Bot commented Dec 15, 2018

Copy link
Copy Markdown

This PR has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed if no further activity occurs within 10 days.
Thank you for your contributions.
Community members are welcome to grab these works.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@stale stale Bot added the Stale label Dec 15, 2018
@vexx32

Rain Sallow (/u/ta11ow) (vexx32) commented Dec 16, 2018

Copy link
Copy Markdown
Collaborator

Kirk Munro (@KirkMunro) Looks like Ilya (@iSazonov) has created a place for the xUnit tests in #8356 😄

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@stale stale Bot removed the Stale label Dec 16, 2018
@iSazonov

Ilya (iSazonov) commented Dec 16, 2018

Copy link
Copy Markdown
Collaborator

Yes, binary tests was moved to new folder. Now all tests run parallel (excluding macOS).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

iSazonov
Ilya (iSazonov) reviewed Mar 1, 2019
View reviewed changes
Comment thread test/powershell/engine/Api/MultithreadedEngine.Tests.ps1 Resolved

Uh oh!

There was an error while loading. Please reload this page.

Kirk Munro (KirkMunro) added 2 commits March 1, 2019 14:13
@KirkMunro
CodeFactor changes
429ba36
@KirkMunro
CodeFactor changes
b4c2f59
daxian-dbw
Dongbo Wang (daxian-dbw) requested changes Mar 1, 2019
View reviewed changes
Comment thread src/System.Management.Automation/engine/hostifaces/PowerShell.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/System.Management.Automation/engine/hostifaces/PowerShell.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread test/powershell/engine/Api/MultithreadedEngine.Tests.ps1 Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread test/powershell/engine/Api/MultithreadedEngine.Tests.ps1 Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread test/powershell/engine/Api/MultithreadedEngine.Tests.ps1 Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread test/powershell/engine/Api/MultithreadedEngine.Tests.ps1 Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread test/powershell/engine/Api/MultithreadedEngine.Tests.ps1 Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1 Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread test/powershell/engine/Api/MultithreadedEngine.Tests.ps1 Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread test/xUnit/csharp/test_PowerShell.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

@KirkMunro
review updates, more tests, some refactoring
3d3aff0
daxian-dbw
Dongbo Wang (daxian-dbw) requested changes Mar 2, 2019
View reviewed changes
Comment thread src/System.Management.Automation/engine/hostifaces/PowerShell.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread test/powershell/engine/Api/TaskBasedAsyncPowerShellAPI.Tests.ps1 Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread test/powershell/engine/Api/TaskBasedAsyncPowerShellAPI.Tests.ps1 Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread test/powershell/engine/Api/TaskBasedAsyncPowerShellAPI.Tests.ps1 Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread test/powershell/engine/Api/TaskBasedAsyncPowerShellAPI.Tests.ps1 Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread test/powershell/engine/Api/TaskBasedAsyncPowerShellAPI.Tests.ps1 Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread test/xUnit/csharp/test_PowerShell.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread test/xUnit/csharp/test_PowerShell.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread test/xUnit/csharp/test_PowerShell.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread test/xUnit/csharp/test_PowerShell.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

daxian-dbw
Dongbo Wang (daxian-dbw) requested changes Mar 2, 2019
View reviewed changes
Comment thread test/powershell/engine/Api/TaskBasedAsyncPowerShellAPI.Tests.ps1 Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread test/xUnit/csharp/test_PowerShell.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

@daxian-dbw Dongbo Wang (daxian-dbw) added the CL-Engine Indicates that a PR should be marked as an engine change in the Change Log label Mar 2, 2019
@daxian-dbw Dongbo Wang (daxian-dbw) changed the title WIP: Add 5 InvokeAsync overloads to S.M.A.PowerShell Add 5 'InvokeAsync' overloads and 'StopAsync' to the 'PowerShell' type Mar 2, 2019
Kirk Munro (KirkMunro) added 7 commits March 3, 2019 13:06
@KirkMunro
Codacy changes
006e56b
@KirkMunro
Updates based on @daxian-dbw's feedback
3ad47f3
@KirkMunro
replace code with Wait-UntilTrue invocation
af6db95
@KirkMunro
refactor code (replace with Wait-UntilTrue)
2974397
@KirkMunro
correction to earlier refactoring of test
12645db
@KirkMunro
fixes to PowerShell engine async tests
34d4b82
@KirkMunro
fixed incorrect waiting logic in C# tests
54cfc7a
daxian-dbw
Dongbo Wang (daxian-dbw) requested changes Mar 3, 2019
View reviewed changes

@daxian-dbw Dongbo Wang (daxian-dbw) left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You xUnit tests were failing in CIs. Please fix them. I'm also fine that you remove the xUnit tests for this PR.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/System.Management.Automation/engine/hostifaces/PowerShell.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Kirk Munro (KirkMunro) added 2 commits March 3, 2019 20:39
@KirkMunro
more changes in response to PR feedback
957ec77
@KirkMunro
added comment to new format views
c224fac
@KirkMunro

Kirk Munro (KirkMunro) commented Mar 4, 2019

Copy link
Copy Markdown
Contributor Author

You xUnit tests were failing in CIs. Please fix them. I'm also fine that you remove the xUnit tests for this PR.

I removed them since they were just duplicates of the Pester tests, and I'm not set up at the moment to easily test C# Unit tests (hence the issues with the CI not working).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@KirkMunro
PR review change
298cfe0
@KirkMunro

Kirk Munro (KirkMunro) commented Mar 4, 2019

Copy link
Copy Markdown
Contributor Author

Pending any further feedback, I think this PR is good to go with enough tests to cover the new Async APIs well enough.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

daxian-dbw
Dongbo Wang (daxian-dbw) approved these changes Mar 4, 2019
View reviewed changes

@daxian-dbw Dongbo Wang (daxian-dbw) left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@daxian-dbw
Dongbo Wang (daxian-dbw) merged commit 45aba2a into PowerShell:master Mar 6, 2019
@KirkMunro
Kirk Munro (KirkMunro) deleted the powershell-invokeasync-methods branch March 6, 2019 18:10
@iSazonov

Ilya (iSazonov) commented Mar 6, 2019

Copy link
Copy Markdown
Collaborator

Kirk Munro (@KirkMunro) Thanks for your contribution!

KirkMunro reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@iSazonov Ilya (iSazonov) mentioned this pull request Mar 7, 2019
Update the task-based async APIs added to PowerShell to return a Task object directly #9079
Merged
4 of 11 tasks
@daxian-dbw Dongbo Wang (daxian-dbw) added this to the 6.2.0 milestone Mar 11, 2019
Travis Plunk (TravisEz13) pushed a commit that referenced this pull request Mar 13, 2019
@KirkMunro @TravisEz13
Add 5 'InvokeAsync' overloads and 'StopAsync' to the 'PowerShell' type (
7482cbf
#8056)
Thatgfsj (Thatgfsj) pushed a commit to Thatgfsj-contribs/PowerShell that referenced this pull request Aug 6, 2026
@KirkMunro @daxian-dbw
Add 5 'InvokeAsync' overloads and 'StopAsync' to the 'PowerShell' type (
3f9af14
PowerShell#8056)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@iSazonov Ilya (iSazonov) iSazonov left review comments
@daxian-dbw Dongbo Wang (daxian-dbw) daxian-dbw approved these changes
+1 more reviewer
@BrucePay Bruce Payette (BrucePay) BrucePay approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@daxian-dbw Dongbo Wang (daxian-dbw)

Labels

CL-Engine Indicates that a PR should be marked as an engine change in the Change Log Committee-Reviewed PS-Committee has reviewed this and made a decision

Projects

None yet

Milestone

6.2.0

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

8 participants

@KirkMunro @iSazonov @adityapatwardhan @SteveL-MSFT @daxian-dbw @vexx32 @anmenaga @BrucePay
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.