From 6792de548caf9e22c7712a47485d69a50e8f0620 Mon Sep 17 00:00:00 2001 From: Dongbo Wang Date: Thu, 18 Apr 2019 14:17:31 -0700 Subject: [PATCH 1/2] Make sure generate the OnIdle event when there are other subscribers --- PSReadLine/ReadLine.cs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/PSReadLine/ReadLine.cs b/PSReadLine/ReadLine.cs index 980c7c0db..2bc684d43 100644 --- a/PSReadLine/ReadLine.cs +++ b/PSReadLine/ReadLine.cs @@ -206,7 +206,7 @@ internal static PSKeyInfo ReadKey() bool runPipelineForEventProcessing = false; foreach (var sub in eventSubscribers) { - if (sub.SourceIdentifier.Equals("PowerShell.OnIdle", StringComparison.OrdinalIgnoreCase)) + if (sub.SourceIdentifier.Equals(PSEngineEvent.OnIdle, StringComparison.OrdinalIgnoreCase)) { // There is an OnIdle event. We're idle because we timed out. Normally // PowerShell generates this event, but PowerShell assumes the engine is not @@ -216,15 +216,13 @@ internal static PSKeyInfo ReadKey() runPipelineForEventProcessing = true; break; } - - // If there are any event subscribers that have an action (which might - // write to the console) and have a source object (i.e. aren't engine - // events), run a tiny useless bit of PowerShell so that the events - // can be processed. - if (sub.Action != null && sub.SourceObject != null) + else if (sub.Action != null && sub.SourceObject != null) { + // If there are any event subscribers that have an action (which might + // write to the console) and have a source object (i.e. aren't engine + // events), run a tiny useless bit of PowerShell so that the events + // can be processed. runPipelineForEventProcessing = true; - break; } } From 3c15c761ccd6b5a47b1d4a542ab8677bcd66900e Mon Sep 17 00:00:00 2001 From: Dongbo Wang Date: Thu, 18 Apr 2019 15:12:44 -0700 Subject: [PATCH 2/2] Address comments --- PSReadLine/ReadLine.cs | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/PSReadLine/ReadLine.cs b/PSReadLine/ReadLine.cs index 2bc684d43..fb07be6a0 100644 --- a/PSReadLine/ReadLine.cs +++ b/PSReadLine/ReadLine.cs @@ -206,26 +206,22 @@ internal static PSKeyInfo ReadKey() bool runPipelineForEventProcessing = false; foreach (var sub in eventSubscribers) { + runPipelineForEventProcessing = true; if (sub.SourceIdentifier.Equals(PSEngineEvent.OnIdle, StringComparison.OrdinalIgnoreCase)) { // There is an OnIdle event. We're idle because we timed out. Normally // PowerShell generates this event, but PowerShell assumes the engine is not // idle because it called PSConsoleHostReadLine which isn't returning. // So we generate the event instead. - _singleton._engineIntrinsics.Events.GenerateEvent("PowerShell.OnIdle", null, null, null); - runPipelineForEventProcessing = true; + _singleton._engineIntrinsics.Events.GenerateEvent(PSEngineEvent.OnIdle, null, null, null); + + // Break out so we don't genreate more than one 'OnIdle' event for a timeout. break; } - else if (sub.Action != null && sub.SourceObject != null) - { - // If there are any event subscribers that have an action (which might - // write to the console) and have a source object (i.e. aren't engine - // events), run a tiny useless bit of PowerShell so that the events - // can be processed. - runPipelineForEventProcessing = true; - } } + // If there are any event subscribers, run a tiny useless PowerShell pipeline + // so that the events can be processed. if (runPipelineForEventProcessing) { if (ps == null)