Skip to content

Commit e64acec

Browse files
authored
Make sure to generate the 'OnIdle' event when there are other subscribers (#899)
1 parent c197e7e commit e64acec

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

PSReadLine/ReadLine.cs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -206,28 +206,22 @@ internal static PSKeyInfo ReadKey()
206206
bool runPipelineForEventProcessing = false;
207207
foreach (var sub in eventSubscribers)
208208
{
209-
if (sub.SourceIdentifier.Equals("PowerShell.OnIdle", StringComparison.OrdinalIgnoreCase))
209+
runPipelineForEventProcessing = true;
210+
if (sub.SourceIdentifier.Equals(PSEngineEvent.OnIdle, StringComparison.OrdinalIgnoreCase))
210211
{
211212
// There is an OnIdle event. We're idle because we timed out. Normally
212213
// PowerShell generates this event, but PowerShell assumes the engine is not
213214
// idle because it called PSConsoleHostReadLine which isn't returning.
214215
// So we generate the event instead.
215-
_singleton._engineIntrinsics.Events.GenerateEvent("PowerShell.OnIdle", null, null, null);
216-
runPipelineForEventProcessing = true;
217-
break;
218-
}
216+
_singleton._engineIntrinsics.Events.GenerateEvent(PSEngineEvent.OnIdle, null, null, null);
219217

220-
// If there are any event subscribers that have an action (which might
221-
// write to the console) and have a source object (i.e. aren't engine
222-
// events), run a tiny useless bit of PowerShell so that the events
223-
// can be processed.
224-
if (sub.Action != null && sub.SourceObject != null)
225-
{
226-
runPipelineForEventProcessing = true;
218+
// Break out so we don't genreate more than one 'OnIdle' event for a timeout.
227219
break;
228220
}
229221
}
230222

223+
// If there are any event subscribers, run a tiny useless PowerShell pipeline
224+
// so that the events can be processed.
231225
if (runPipelineForEventProcessing)
232226
{
233227
if (ps == null)

0 commit comments

Comments
 (0)