How to create C# async powershell method? How to create C# async powershell method? powershell powershell

How to create C# async powershell method?


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.