Add Process.IsRunning(int processId) static extension method#10
Add Process.IsRunning(int processId) static extension method#10
Process.IsRunning(int processId) static extension method#10Conversation
Agent-Logs-Url: https://github.com/Tyrrrz/PowerKit/sessions/1d46a42a-6dbc-4bcd-b0a6-e32434980772 Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>
Agent-Logs-Url: https://github.com/Tyrrrz/PowerKit/sessions/1d46a42a-6dbc-4bcd-b0a6-e32434980772 Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>
Agent-Logs-Url: https://github.com/Tyrrrz/PowerKit/sessions/2314dced-9a6c-4bae-b31c-81016f1040a9 Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds a Process.IsRunning(int processId) helper intended to let callers check whether a PID refers to a currently-running process.
Changes:
- Introduces a
Processextension block withIsRunning(int processId)implemented viaGetProcessById+HasExited. - Adds tests for a running PID (
Environment.ProcessId) and a non-running PID (a short-lived spawned process).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| PowerKit/Extensions/ProcessExtensions.cs | Adds the Process.IsRunning(int) API implementation. |
| PowerKit.Tests/ProcessExtensionsTests.cs | Adds unit tests validating IsRunning for running and exited processes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| try | ||
| { | ||
| using var process = Process.GetProcessById(processId); | ||
| return !process.HasExited; | ||
| } | ||
| catch | ||
| { | ||
| return false; | ||
| } |
There was a problem hiding this comment.
A bare catch swallows all exceptions, including ones that typically should not be suppressed (and makes debugging harder if unexpected failures occur). Prefer catching the specific exceptions that represent 'not running / cannot be queried' (e.g., process not found / access denied) and let other exceptions surface, or use an exception filter to return false only for the expected cases.
Adds a static extension on
Processto check whether a process with a given ID is currently running.Changes
ProcessExtensions.cs— new extension block onProcesswith a single static methodIsRunning(int processId): callsGetProcessById, checksHasExited, and returnsfalseon any exception (process not found, access denied, etc.)ProcessExtensionsTests.cs— tests covering a live process (Environment.ProcessId) and an already-exited processUsage