How to create C# async powershell method?

前端 未结 1 1104
伪装坚强ぢ
伪装坚强ぢ 2021-01-02 02:01

So I want to create a way to run a powershell script asynchronously. The below code is what I have so far, but it doesn\'t seem to be async because it locks up the applicati

相关标签:
1条回答
  • 2021-01-02 02:53

    You are calling it asynchronously.

    However, you are then defeating the purpose by synchronously waiting for the asynchronous operation to finish, by calling EndInvoke().

    To actually run it asynchronously, you need to make your method asynchronous too.
    You can do that by calling Task.Factory.FromAsync(...) to get a Task<PSObject> for the asynchronous operation, then using await.

    0 讨论(0)
提交回复
热议问题