protected virtual void Dispose(bool disposing) { lock (_disposeSyncObject) { if (_isDisposed || !disposing) { return; } while (NestedPromptLevel > 1) { _consoleReader?.StopCommandLoop(); var currentFrame = CurrentFrame; if (currentFrame.FrameType.HasFlag(PromptNestFrameType.Debug)) { _versionSpecificOperations.StopCommandInDebugger(_powerShellContext); currentFrame.ThreadController.StartThreadExit(DebuggerResumeAction.Stop); currentFrame.WaitForFrameExit(CancellationToken.None); continue; } if (currentFrame.FrameType.HasFlag(PromptNestFrameType.NestedPrompt)) { _powerShellContext.ExitAllNestedPrompts(); continue; } currentFrame.PowerShell.BeginStop(null, null); currentFrame.WaitForFrameExit(CancellationToken.None); } _consoleReader?.StopCommandLoop(); _readLineFrame.Dispose(); CurrentFrame.Dispose(); _frameStack.Clear(); _powerShellContext = null; _consoleReader = null; _isDisposed = true; } }