What happens when you click Stop
Everyone writes an accidental while ($true) eventually. The interesting question is what the next ten seconds look like.
Here they’re uneventful. Click the toolbar’s Stop button and the run ends promptly, the session returns to idle, and your next command executes normally with all your variables intact. Our release gate verifies that exact sequence on every build: start a deliberate thirty-second sleep, click Stop, then run a follow-up command and confirm it completes long before the thirty seconds would have elapsed. The assertion is about the afterward, because a stop that leaves the session wedged hasn’t really stopped anything.
The plumbing matters more than it looks like it should. Stopping a PowerShell pipeline synchronously blocks the calling thread until the pipeline acknowledges, and under load that acknowledgment can take a while. Wire a Stop button naively and clicking it can freeze the app. A frozen window whose last click was “stop” is a special kind of embarrassing. So the stop is issued asynchronously, and the pipeline’s termination surfaces through the normal completion path while the UI keeps working.
The related machinery follows the same pattern. If you set an execution timeout in Settings (it’s off by default), a run that exceeds it is stopped through the same path, with a message naming the timeout that fired. During a debug session, Break All (Ctrl+B) is the gentler option: instead of ending a runaway, it pauses it at the next statement, which turns “it’s stuck somewhere” into a debugger stop with a call stack. Often that’s what you wanted, a look at where it lives before deciding what to do with it. Shift+F5 ends a debug session without discarding session state.
One property runs through all of it: the session survives. Some hosts treat a stopped run as contaminated and quietly rebuild the runspace, taking your variables with it. Here the stop ends the pipeline. The session, with its variables, functions, modules, and history, stays. Losing an afternoon of accumulated state as punishment for one loop would be a second bug on top of the first.