Skip to content

Commit 65be868

Browse files
TylerLeonhardtdaxian-dbw
authored andcommitted
Fix for a nullref thrown when PSES calls ForcePSEventHandling (#1097)
1 parent 197a3fd commit 65be868

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

PSReadLine/ReadLine.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,10 @@ private PSConsoleReadLine()
620620
_savedCurrentLine = new HistoryItem();
621621
_queuedKeys = new Queue<PSKeyInfo>();
622622

623+
// Initialize this event handler early because it could be used by PowerShell
624+
// Editor Services before 'DelayedOneTimeInitialize' runs.
625+
_forceEventWaitHandle = new AutoResetEvent(false);
626+
623627
string hostName = null;
624628
// This works mostly by luck - we're not doing anything to guarantee the constructor for our
625629
// singleton is called on a thread with a runspace, but it is happening by coincidence.
@@ -802,7 +806,6 @@ private void DelayedOneTimeInitialize()
802806

803807
_singleton._readKeyWaitHandle = new AutoResetEvent(false);
804808
_singleton._keyReadWaitHandle = new AutoResetEvent(false);
805-
_singleton._forceEventWaitHandle = new AutoResetEvent(false);
806809
_singleton._closingWaitHandle = new ManualResetEvent(false);
807810
_singleton._requestKeyWaitHandles = new WaitHandle[] {_singleton._keyReadWaitHandle, _singleton._closingWaitHandle, _defaultCancellationToken.WaitHandle, _singleton._forceEventWaitHandle};
808811
_singleton._threadProcWaitHandles = new WaitHandle[] {_singleton._readKeyWaitHandle, _singleton._closingWaitHandle};

0 commit comments

Comments
 (0)