Repository navigation
Expand file tree
/
Copy pathStop-Thread.ps1
More file actions
47 lines (37 loc) · 1.54 KB
/
Copy pathStop-Thread.ps1
File metadata and controls
47 lines (37 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<#
.SYNOPSIS
Request termination for a registered thread.
.DESCRIPTION
`Stop-Thread` marks a thread's state as `TERMINATED` in the global thread
registry. It validates the provided thread id and returns structured results
using `Write-FunctionReturnValue` when errors occur.
.PARAMETER ThreadId
| Name | Type | Description | Default |
|----------|---------------|------------------------------|---------|
| ThreadId | System.String | The id of the thread to stop | $null |
.OUTPUTS
System.Management.Automation.PSCustomObject -- Strukturierter Rueckgabewert bei Fehler (via Write-FunctionReturnValue); None bei Erfolg.
.EXAMPLE
PS> Stop-Thread -ThreadId $tid
.NOTES
The actual runspace shutdown and cleanup is handled by the housekeeper loop.
SPDX-FileCopyrightText: 2026 Icinga GmbH <https://icinga.com>
SPDX-License-Identifier: GPL-3.0-or-later
#>
function Stop-Thread()
{
param (
[string]$ThreadId = $null
);
# Stops a specified Thread by setting its state to TERMINATED
# Validate the ThreadId parameter
if ([string]::IsNullOrEmpty($ThreadId)) {
return (Write-FunctionReturnValue -ReturnValue 'ThreadIdEmpty');
}
# Check if the specified thread exists
if ($null -eq (Get-GlobalRuntimeVariable).Public.Threading.Threads.$ThreadId) {
return (Write-FunctionReturnValue -ReturnValue 'ThreadNotFound' -Data @{ 'ThreadId' = $ThreadId });
}
# Set the thread state to TERMINATED
(Get-GlobalRuntimeVariable).Public.Threading.Threads.$ThreadId.State = 'TERMINATED';
}