From 62d06c715c872083fda6fd22a9ea528421cd32e3 Mon Sep 17 00:00:00 2001 From: Tyler Leonhardt Date: Sat, 12 Oct 2019 02:55:20 +0200 Subject: [PATCH 1/2] move constructor at the type init --- PSReadLine/ReadLine.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/PSReadLine/ReadLine.cs b/PSReadLine/ReadLine.cs index fb07be6a0..6bcc60495 100644 --- a/PSReadLine/ReadLine.cs +++ b/PSReadLine/ReadLine.cs @@ -52,7 +52,7 @@ public partial class PSConsoleReadLine : IPSConsoleReadLineMockableMethods private Thread _readKeyThread; private AutoResetEvent _readKeyWaitHandle; private AutoResetEvent _keyReadWaitHandle; - private AutoResetEvent _forceEventWaitHandle; + private AutoResetEvent _forceEventWaitHandle = new AutoResetEvent(false); private CancellationToken _cancelReadCancellationToken; internal ManualResetEvent _closingWaitHandle; private WaitHandle[] _threadProcWaitHandles; @@ -802,7 +802,6 @@ private void DelayedOneTimeInitialize() _singleton._readKeyWaitHandle = new AutoResetEvent(false); _singleton._keyReadWaitHandle = new AutoResetEvent(false); - _singleton._forceEventWaitHandle = new AutoResetEvent(false); _singleton._closingWaitHandle = new ManualResetEvent(false); _singleton._requestKeyWaitHandles = new WaitHandle[] {_singleton._keyReadWaitHandle, _singleton._closingWaitHandle, _defaultCancellationToken.WaitHandle, _singleton._forceEventWaitHandle}; _singleton._threadProcWaitHandles = new WaitHandle[] {_singleton._readKeyWaitHandle, _singleton._closingWaitHandle}; From 50a9996934ba51ea7c15bf75b607edf7fcdd26a7 Mon Sep 17 00:00:00 2001 From: Dongbo Wang Date: Tue, 29 Oct 2019 16:33:20 -0700 Subject: [PATCH 2/2] Move the initialization to the constructor --- PSReadLine/ReadLine.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/PSReadLine/ReadLine.cs b/PSReadLine/ReadLine.cs index 6bcc60495..1cdc94417 100644 --- a/PSReadLine/ReadLine.cs +++ b/PSReadLine/ReadLine.cs @@ -52,7 +52,7 @@ public partial class PSConsoleReadLine : IPSConsoleReadLineMockableMethods private Thread _readKeyThread; private AutoResetEvent _readKeyWaitHandle; private AutoResetEvent _keyReadWaitHandle; - private AutoResetEvent _forceEventWaitHandle = new AutoResetEvent(false); + private AutoResetEvent _forceEventWaitHandle; private CancellationToken _cancelReadCancellationToken; internal ManualResetEvent _closingWaitHandle; private WaitHandle[] _threadProcWaitHandles; @@ -620,6 +620,10 @@ private PSConsoleReadLine() _savedCurrentLine = new HistoryItem(); _queuedKeys = new Queue(); + // Initialize this event handler early because it could be used by PowerShell + // Editor Services before 'DelayedOneTimeInitialize' runs. + _forceEventWaitHandle = new AutoResetEvent(false); + string hostName = null; // This works mostly by luck - we're not doing anything to guarantee the constructor for our // singleton is called on a thread with a runspace, but it is happening by coincidence.