Skip to content

Add Process.IsRunning(int processId) static extension method#10

Merged
Tyrrrz merged 4 commits intoprimefrom
copilot/add-process-isrunning-method
Apr 12, 2026
Merged

Add Process.IsRunning(int processId) static extension method#10
Tyrrrz merged 4 commits intoprimefrom
copilot/add-process-isrunning-method

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 12, 2026

Adds a static extension on Process to check whether a process with a given ID is currently running.

Changes

  • ProcessExtensions.cs — new extension block on Process with a single static method IsRunning(int processId): calls GetProcessById, checks HasExited, and returns false on any exception (process not found, access denied, etc.)
  • ProcessExtensionsTests.cs — tests covering a live process (Environment.ProcessId) and an already-exited process

Usage

if (Process.IsRunning(pid))
{
    // process is alive
}

@Tyrrrz Tyrrrz added the enhancement New feature or request label Apr 12, 2026
RedirectStandardOutput = true
})!;

process.WaitForExit();
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the async version of thsi method @copilot

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 2708d82 — switched to await process.WaitForExitAsync().

Copilot AI requested a review from Tyrrrz April 12, 2026 15:55
@Tyrrrz Tyrrrz marked this pull request as ready for review April 12, 2026 15:59
Copilot AI review requested due to automatic review settings April 12, 2026 15:59
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 Process extension block with IsRunning(int processId) implemented via GetProcessById + 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.

Comment thread PowerKit/Extensions/ProcessExtensions.cs
Comment on lines +14 to +22
try
{
using var process = Process.GetProcessById(processId);
return !process.HasExited;
}
catch
{
return false;
}
Copy link

Copilot AI Apr 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment thread PowerKit.Tests/ProcessExtensionsTests.cs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants