From a21f09c7d01d0a9be1d639a48bcbd15d1ced45c3 Mon Sep 17 00:00:00 2001 From: Dongbo Wang Date: Thu, 4 Apr 2019 17:04:41 -0700 Subject: [PATCH 1/2] Fixing test run crash by not passing script block to the callback --- .../engine/hostifaces/PowerShell.cs | 18 ++++++++++++++++++ .../Api/TaskBasedAsyncPowerShellAPI.Tests.ps1 | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/System.Management.Automation/engine/hostifaces/PowerShell.cs b/src/System.Management.Automation/engine/hostifaces/PowerShell.cs index 2014d3d5cb1..375108d2310 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 casted from a script block. + /// The callback could be invoked from a thread without a default Runspace and a delegate casted 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 casted from a script block. + /// The callback could be invoked from a thread without a default Runspace and a delegate casted 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 casted from a script block. + /// The callback could be invoked from a thread without a default Runspace and a delegate casted 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 casted from a script block. + /// The callback could be invoked from a thread without a default Runspace and a delegate casted 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 casted from a script block. + /// The callback could be invoked from a thread without a default Runspace and a delegate casted 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 casted from a script block. + /// The callback could be invoked from a thread without a default Runspace and a delegate casted 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 From 6c8b43bc43ca9bdae311b267e22c49912e0b652c Mon Sep 17 00:00:00 2001 From: Dongbo Wang Date: Thu, 4 Apr 2019 17:13:03 -0700 Subject: [PATCH 2/2] Fix typos --- .../engine/hostifaces/PowerShell.cs | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/System.Management.Automation/engine/hostifaces/PowerShell.cs b/src/System.Management.Automation/engine/hostifaces/PowerShell.cs index 375108d2310..a2ec0557644 100644 --- a/src/System.Management.Automation/engine/hostifaces/PowerShell.cs +++ b/src/System.Management.Automation/engine/hostifaces/PowerShell.cs @@ -2915,8 +2915,8 @@ 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 casted from a script block. - /// The callback could be invoked from a thread without a default Runspace and a delegate casted from + /// 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. /// /// @@ -3039,8 +3039,8 @@ 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 casted from a script block. - /// The callback could be invoked from a thread without a default Runspace and a delegate casted from + /// 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. /// /// @@ -3164,8 +3164,8 @@ 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 casted from a script block. - /// The callback could be invoked from a thread without a default Runspace and a delegate casted from + /// 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. /// /// @@ -3273,8 +3273,8 @@ 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 casted from a script block. - /// The callback could be invoked from a thread without a default Runspace and a delegate casted from + /// 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. /// /// @@ -3745,8 +3745,8 @@ 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 casted from a script block. - /// The callback could be invoked from a thread without a default Runspace and a delegate casted from + /// 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. /// /// @@ -3809,8 +3809,8 @@ 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 casted from a script block. - /// The callback could be invoked from a thread without a default Runspace and a delegate casted from + /// 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. /// ///