@@ -1207,7 +1207,18 @@ private Runspace CreateInitialRunspace(InitialSessionState initialSessionState)
1207
1207
return runspace ;
1208
1208
}
1209
1209
1210
- // NOTE: This token is received from PSReadLine, and it _is_ the ReadKey cancellation token!
1210
+ /// <summary>
1211
+ /// This delegate is handed to PSReadLine and overrides similar logic within its `ReadKey`
1212
+ /// method. Essentially we're replacing PowerShell's `OnIdle` handler since the PowerShell
1213
+ /// engine isn't idle when we're sitting in PSReadLine's `ReadKey` loop. In our case we also
1214
+ /// use this idle time to process queued tasks by executing those that can run in the
1215
+ /// background, and canceling the foreground task if a queued tasks requires the foreground.
1216
+ /// Finally, if and only if we have to, we run an artificial pipeline to force PowerShell's
1217
+ /// own event processing.
1218
+ /// </summary>
1219
+ /// <param name="idleCancellationToken">
1220
+ /// This token is received from PSReadLine, and it is the ReadKey cancellation token!
1221
+ /// </param>
1211
1222
internal void OnPowerShellIdle ( CancellationToken idleCancellationToken )
1212
1223
{
1213
1224
IReadOnlyList < PSEventSubscriber > eventSubscribers = _mainRunspaceEngineIntrinsics . Events . Subscribers ;
@@ -1257,10 +1268,15 @@ internal void OnPowerShellIdle(CancellationToken idleCancellationToken)
1257
1268
1258
1269
// We didn't end up executing anything in the background,
1259
1270
// so we need to run a small artificial pipeline instead
1260
- // to force event processing
1271
+ // to force event processing.
1261
1272
if ( runPipelineForEventProcessing )
1262
1273
{
1263
- InvokePSCommand ( new PSCommand ( ) . AddScript ( "0" , useLocalScope : true ) , executionOptions : null , CancellationToken . None ) ;
1274
+ InvokePSCommand (
1275
+ new PSCommand ( ) . AddScript (
1276
+ "[System.Diagnostics.DebuggerHidden()]param() 0" ,
1277
+ useLocalScope : true ) ,
1278
+ executionOptions : null ,
1279
+ CancellationToken . None ) ;
1264
1280
}
1265
1281
}
1266
1282
0 commit comments