When getting dynamic parameters from a thread other than the pipeline
thread, the call to CommandInfo.Parameters internally tries to get
back to it using the PowerShell EventManager. If dynamic parameters
are being obtained from an event that is being processed by the
EventManager then a deadlock will occur.
This change routes the call to CommandInfo.Parameters to the main
thread using AsyncCmdlet.ExecuteOnMainThread, bypassing the
EventManager.
I've taken a look at this, and it feels like it's the right fix and doesn't touch too much.
Fix from @SeeminglyScience:
I've taken a look at this, and it feels like it's the right fix and doesn't touch too much.
Happy to take responsibility for it.