Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ParallelKit.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# graceful Ctrl+C/window-close handling for Windows PowerShell 5.1 and
# PowerShell 7.
#
# Version 4.0 - https://github.com/HalRiveria/PowerShell-ParallelKit
# Version 4.1 - https://github.com/HalRiveria/PowerShell-ParallelKit
# (Initialize-ParallelKit reports the version too: change both together. The
# module's manifest takes it from here.)
# Copyright (c) 2026 HalRiveria. MIT License: keep this notice with any copy;
Expand Down Expand Up @@ -1256,7 +1256,7 @@ function Initialize-ParallelKit {
$jobOk = Initialize-PkChildProcessJob
# The header's Version line: the version PR changes both, and the harness
# checks they match.
$version = [version]'4.0'
$version = [version]'4.1'
return [pscustomobject][ordered]@{ AbortHandler = $handlerOk; ChildProcessJob = $jobOk; Version = $version; StartMode = [PkChildProcessJob]::StartMode }
}

Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ Each one has built-in help: `Get-Help Invoke-PkProcessBatch -Full` shows its par

## Setup

Requires Windows, with Windows PowerShell 5.1 or PowerShell 7. Download `ParallelKit.ps1` from the [Releases page](https://github.com/HalRiveria/PowerShell-ParallelKit/releases) (this README describes version 4.0 and later), put it in your project, and dot-source it from your script:
Requires Windows, with Windows PowerShell 5.1 or PowerShell 7. Download `ParallelKit.ps1` from the [Releases page](https://github.com/HalRiveria/PowerShell-ParallelKit/releases) (this README describes version 4.1 and later), put it in your project, and dot-source it from your script:

```powershell
. "$PSScriptRoot\ParallelKit.ps1"
Expand Down Expand Up @@ -180,7 +180,7 @@ Import-Module C:\Modules\ParallelKit

Installed, or built into a `ParallelKit` folder somewhere on `$env:PSModulePath`, `Import-Module ParallelKit` finds it by name, and so does a call to any of its functions without importing it first. The rest of this README applies either way.

The module's version always has three parts: the kit's X.Y (what `Initialize-ParallelKit` reports) is the module's X.Y.0, and an X.Y.Z version stays as it is. So for 4.0, `Get-Module ParallelKit` shows 4.0.0, and that's the version `Import-Module -RequiredVersion` takes.
The module's version always has three parts: the kit's X.Y (what `Initialize-ParallelKit` reports) is the module's X.Y.0, and an X.Y.Z version stays as it is. So for 4.1, `Get-Module ParallelKit` shows 4.1.0, and that's the version `Import-Module -RequiredVersion` takes.

<details>
<summary>If the import is refused</summary>
Expand Down Expand Up @@ -673,7 +673,7 @@ Other pieces: `Request-PkAbort` triggers the same abort from code. `Test-PkAbort

- Windows only (console and Job Object APIs), on Windows PowerShell 5.1 or PowerShell 7.
- Run it in a PowerShell console window or an editor's terminal (graceful Ctrl+C tested in Windows Terminal, Visual Studio's built-in terminal and VS Code's terminal, including the PowerShell extension's). The Windows PowerShell ISE isn't supported: tested there, the kit loads and runs, but the ISE has no console, so Ctrl+C stops the script outright, with no graceful drain and no cleanup callbacks.
- It needs FullLanguage mode, since it compiles a little C# with `Add-Type` when loaded. On a machine locked down to Constrained Language Mode (usually by AppLocker or Windows Defender Application Control), loading it fails with a message saying so. Some endpoint security products also flag scripts that compile code calling Windows APIs at runtime; if yours blocks the kit, that's the likely reason.
- It needs FullLanguage mode, since it compiles a little C# with `Add-Type` when loaded. On a machine locked down to Constrained Language Mode (usually by AppLocker or Windows Defender Application Control), loading it fails with a message saying so. Some endpoint security products also flag scripts that compile code calling Windows APIs at runtime; if yours blocks the kit, that's the likely reason. On Windows PowerShell 5.1 the compile runs `csc.exe`, which writes a few temporary files to `%TEMP%` and deletes them during the load. And with no logging policy set, PowerShell records the kit as a Warning-level script block logging event (4104) on every load, on 5.1 and 7, because `Add-Type` and the reflection calls are on its built-in list of suspicious words; any script that uses `Add-Type` is logged the same way.
- After updating the kit, or changing `ParallelKit.ps1` yourself, start a new PowerShell window. A session keeps the kit's compiled parts until it closes, and the kit tells you if a different version's are already loaded.
- One `Invoke-PkRun` at a time per PowerShell process: a call made while one is already running, nested or from another runspace, just runs inside it. Several dispatchers can run at once inside one run (one per runspace job, say); they share its abort state and can share a `SemaphoreSlim` to enforce a combined concurrency limit.
- A worker stuck inside a long .NET call can't be interrupted. Force-stop stops waiting for it and returns. The worker is NOT killed: once that call returns it can carry on to the end of its script. Before any step that can't be undone (deleting a source file, say), have the worker check `Test-PkCancelRequested` and skip the step if it's true.
Expand Down