diff --git a/src/System.Management.Automation/engine/hostifaces/PowerShell.cs b/src/System.Management.Automation/engine/hostifaces/PowerShell.cs index 2014d3d5cb1..a2ec0557644 100644 --- a/src/System.Management.Automation/engine/hostifaces/PowerShell.cs +++ b/src/System.Management.Automation/engine/hostifaces/PowerShell.cs @@ -2915,6 +2915,9 @@ public IAsyncResult BeginInvoke(PSDataCollection input) /// /// /// An AsyncCallback to call once the BeginInvoke completes. + /// Note: when using this API in script, don't pass in a delegate that is cast from a script block. + /// The callback could be invoked from a thread without a default Runspace and a delegate cast from + /// a script block would fail in that case. /// /// /// A user supplied state to call the @@ -3036,6 +3039,9 @@ public IAsyncResult BeginInvoke(PSDataCollection input, /// /// /// An AsyncCallback to call once the BeginInvoke completes. + /// Note: when using this API in script, don't pass in a delegate that is cast from a script block. + /// The callback could be invoked from a thread without a default Runspace and a delegate cast from + /// a script block would fail in that case. /// /// /// A user supplied state to call the @@ -3158,6 +3164,9 @@ public Task> InvokeAsync(PSDataCollection input /// /// /// An AsyncCallback to call once the command is invoked. + /// Note: when using this API in script, don't pass in a delegate that is cast from a script block. + /// The callback could be invoked from a thread without a default Runspace and a delegate cast from + /// a script block would fail in that case. /// /// /// A user supplied state to call the @@ -3264,6 +3273,9 @@ public Task> InvokeAsync(PSDataColle /// /// /// An AsyncCallback to call once the command is invoked. + /// Note: when using this API in script, don't pass in a delegate that is cast from a script block. + /// The callback could be invoked from a thread without a default Runspace and a delegate cast from + /// a script block would fail in that case. /// /// /// A user supplied state to call the @@ -3733,6 +3745,9 @@ public void Stop() /// /// /// A AsyncCallback to call once the BeginStop completes. + /// Note: when using this API in script, don't pass in a delegate that is cast from a script block. + /// The callback could be invoked from a thread without a default Runspace and a delegate cast from + /// a script block would fail in that case. /// /// /// A user supplied state to call the @@ -3794,6 +3809,9 @@ public void EndStop(IAsyncResult asyncResult) /// /// /// An AsyncCallback to call once the command is invoked. + /// Note: when using this API in script, don't pass in a delegate that is cast from a script block. + /// The callback could be invoked from a thread without a default Runspace and a delegate cast from + /// a script block would fail in that case. /// /// /// A user supplied state to call the diff --git a/test/powershell/engine/Api/TaskBasedAsyncPowerShellAPI.Tests.ps1 b/test/powershell/engine/Api/TaskBasedAsyncPowerShellAPI.Tests.ps1 index 8130eade2a0..64b12216949 100644 --- a/test/powershell/engine/Api/TaskBasedAsyncPowerShellAPI.Tests.ps1 +++ b/test/powershell/engine/Api/TaskBasedAsyncPowerShellAPI.Tests.ps1 @@ -207,7 +207,7 @@ try { try { $ir = $ps.AddScript("Start-Sleep -Seconds 60").InvokeAsync() Wait-UntilTrue { $ps.InvocationStateInfo.State -eq [System.Management.Automation.PSInvocationState]::Running } - $sr = $ps.StopAsync({}, $null) + $sr = $ps.StopAsync($null, $null) [System.Threading.Tasks.Task]::WaitAll(@($sr)) $sr.IsCompletedSuccessfully | Should -Be $true $ir.IsFaulted | Should -Be $true