3
3
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
4
4
//
5
5
6
- using Microsoft . PowerShell . EditorServices . Utility ;
7
6
using System ;
8
- using System . Globalization ;
9
7
using System . Collections . Generic ;
10
8
using System . Collections . ObjectModel ;
9
+ using System . Globalization ;
10
+ using System . IO ;
11
11
using System . Linq ;
12
+ using System . Management . Automation . Host ;
13
+ using System . Management . Automation . Remoting ;
14
+ using System . Management . Automation . Runspaces ;
12
15
using System . Text ;
13
16
using System . Text . RegularExpressions ;
14
17
using System . Threading ;
15
18
using System . Threading . Tasks ;
19
+ using Microsoft . PowerShell . EditorServices . Session ;
20
+ using Microsoft . PowerShell . EditorServices . Session . Capabilities ;
21
+ using Microsoft . PowerShell . EditorServices . Utility ;
16
22
17
23
namespace Microsoft . PowerShell . EditorServices
18
24
{
19
- using Session ;
20
25
using System . Management . Automation ;
21
- using System . Management . Automation . Host ;
22
- using System . Management . Automation . Runspaces ;
23
- using Microsoft . PowerShell . EditorServices . Session . Capabilities ;
24
- using System . IO ;
25
- using System . Management . Automation . Remoting ;
26
26
27
27
/// <summary>
28
28
/// Manages the lifetime and usage of a PowerShell session.
@@ -33,7 +33,7 @@ public class PowerShellContext : IDisposable, IHostSupportsInteractiveSession
33
33
{
34
34
#region Fields
35
35
36
- private readonly SemaphoreSlim resumeRequestHandle = new SemaphoreSlim ( 1 , 1 ) ;
36
+ private readonly SemaphoreSlim resumeRequestHandle = AsyncUtils . CreateSimpleLockingSemaphore ( ) ;
37
37
38
38
private bool isPSReadLineEnabled ;
39
39
private ILogger logger ;
@@ -48,7 +48,7 @@ public class PowerShellContext : IDisposable, IHostSupportsInteractiveSession
48
48
49
49
private Stack < RunspaceDetails > runspaceStack = new Stack < RunspaceDetails > ( ) ;
50
50
51
- private bool isCommandLoopRestarterSet ;
51
+ private int isCommandLoopRestarterSet ;
52
52
53
53
#endregion
54
54
@@ -307,11 +307,11 @@ public void Initialize(
307
307
this . powerShell ,
308
308
this . ConsoleReader ,
309
309
this . versionSpecificOperations ) ;
310
- this . InvocationEventQueue = InvocationEventQueue . Create ( this , this . PromptNest ) ;
310
+ this . InvocationEventQueue = InvocationEventQueue . Create ( this , this . PromptNest , this . logger ) ;
311
311
312
312
if ( powerShellVersion . Major >= 5 &&
313
313
this . isPSReadLineEnabled &&
314
- PSReadLinePromptContext . TryGetPSReadLineProxy ( initialRunspace , out PSReadLineProxy proxy ) )
314
+ PSReadLinePromptContext . TryGetPSReadLineProxy ( logger , initialRunspace , out PSReadLineProxy proxy ) )
315
315
{
316
316
this . PromptContext = new PSReadLinePromptContext (
317
317
this ,
@@ -1006,9 +1006,9 @@ internal async Task InvokeOnPipelineThread(Action<PowerShell> invocationAction)
1006
1006
invocationAction . Invoke ( this . PromptNest . GetPowerShell ( ) ) ;
1007
1007
}
1008
1008
1009
- internal async Task < string > InvokeReadLine ( bool isCommandLine , CancellationToken cancellationToken )
1009
+ internal async Task < string > InvokeReadLineAsync ( bool isCommandLine , CancellationToken cancellationToken )
1010
1010
{
1011
- return await PromptContext . InvokeReadLine (
1011
+ return await PromptContext . InvokeReadLineAsync (
1012
1012
isCommandLine ,
1013
1013
cancellationToken ) ;
1014
1014
}
@@ -2060,7 +2060,7 @@ private void HandleRunspaceStateChanged(object sender, RunspaceStateEventArgs ar
2060
2060
2061
2061
private void StartCommandLoopOnRunspaceAvailable ( )
2062
2062
{
2063
- if ( this . isCommandLoopRestarterSet )
2063
+ if ( Interlocked . CompareExchange ( ref this . isCommandLoopRestarterSet , 1 , 1 ) == 1 )
2064
2064
{
2065
2065
return ;
2066
2066
}
@@ -2075,12 +2075,12 @@ private void StartCommandLoopOnRunspaceAvailable()
2075
2075
}
2076
2076
2077
2077
( ( Runspace ) runspace ) . AvailabilityChanged -= handler ;
2078
- this . isCommandLoopRestarterSet = false ;
2078
+ Interlocked . Exchange ( ref this . isCommandLoopRestarterSet , 0 ) ;
2079
2079
this . ConsoleReader ? . StartCommandLoop ( ) ;
2080
2080
} ;
2081
2081
2082
2082
this . CurrentRunspace . Runspace . AvailabilityChanged += handler ;
2083
- this . isCommandLoopRestarterSet = true ;
2083
+ Interlocked . Exchange ( ref this . isCommandLoopRestarterSet , 1 ) ;
2084
2084
}
2085
2085
2086
2086
private void OnDebuggerStop ( object sender , DebuggerStopEventArgs e )
0 commit comments