![]() |
VOOZH | about |
dotnet add package Gapotchenko.FX.Diagnostics.Process --version 2026.7.2
NuGet\Install-Package Gapotchenko.FX.Diagnostics.Process -Version 2026.7.2
<PackageReference Include="Gapotchenko.FX.Diagnostics.Process" Version="2026.7.2" />
<PackageVersion Include="Gapotchenko.FX.Diagnostics.Process" Version="2026.7.2" />Directory.Packages.props
<PackageReference Include="Gapotchenko.FX.Diagnostics.Process" />Project file
paket add Gapotchenko.FX.Diagnostics.Process --version 2026.7.2
#r "nuget: Gapotchenko.FX.Diagnostics.Process, 2026.7.2"
#:package Gapotchenko.FX.Diagnostics.Process@2026.7.2
#addin nuget:?package=Gapotchenko.FX.Diagnostics.Process&version=2026.7.2Install as a Cake Addin
#tool nuget:?package=Gapotchenko.FX.Diagnostics.Process&version=2026.7.2Install as a Cake Tool
The module provides extended functionality for process manipulation.
GetParent() is an extension method provided by Gapotchenko.FX.Diagnostics.Process module
for System.Diagnostics.Process class.
GetParent() method returns a parent process of the specified process, or null when the parent process is absent or is no longer running.
Enumerates a chain of parent processes beginning with the closest parent.
Reads environment variables of a process.
The functionality is achieved by reading the process environment block (PEB) at the operating system level.
For example, this is how a PATH environment variable can be retrieved from all running instances of Microsoft Visual Studio:
using Gapotchenko.FX.Diagnostics;
using System;
using System.Diagnostics;
class Program
{
static void Main()
{
var processes = Process.GetProcessesByName("devenv");
if (processes.Length == 0)
Console.WriteLine("Process with a given name not found. Please modify the code and specify the existing process name.");
foreach (var process in processes)
{
Console.WriteLine();
Console.WriteLine("Process with ID {0} has the following value of PATH environment variable:", process.Id);
var env = process.ReadEnvironmentVariables();
string path = env["PATH"];
Console.WriteLine(path);
}
}
}
The method retrieves a set of command-line arguments specified at the process start. The functionality is achieved by reading the process environment block at the operating system level.
using Gapotchenko.FX.Diagnostics;
using System;
using System.Diagnostics;
class Program
{
static void Main()
{
var processes = Process.GetProcessesByName("devenv");
if (processes.Length == 0)
Console.WriteLine("Process with a given name not found. Please modify the code and specify the existing process name.");
foreach (var process in processes)
{
Console.WriteLine(
"Process with ID {0} was started with the following command line: {1}",
process.Id,
process.ReadArguments());
}
}
}
The method retrieves a sequence of command-line arguments specified at the process start.
It is similar to aforementioned ReadArguments() method but returns a sequence of command-line arguments instead of a single command line string.
This fundamental difference may be essential in multi-platform scenarios. For instance, Windows OS natively represents the command line of a process as a single string, while Unix operating systems natively represent the command line as a strongly-typed array of command-line arguments.
Whichever method is used the results are similar, but every method provides a higher degree of detalization for a particular operating system.
Allows to end a process according to a specified mode of operation.
The End() method is interesting and a bit intricate.
The stock Process class already provides a similar Kill() method
which performs an immediate forceful termination of a process without giving it a chance to exit gracefully.
Depending on a kind of process being terminated, Kill() is not always suitable.
For example, it may have devastating consequences if someone kills a Microsoft Visual Studio process without giving it a graceful shutdown.
Lost files, potentially corrupted extensions and so on.
Meet the End() method provided by Gapotchenko.FX.Diagnostics.Process module.
It allows to end a process according to a specified mode of operation.
The default mode of operation is ProcessEndMode.Complete that follows a sequence presented below:
End() method tries to close a main window of the processEnd() method tries to exit the process (suitable for the current process only)The method returns a ProcessEndMode value on completion indicating how the process was actually ended.
Let's take a look on example that tries to end all running instances of Notepad:
using Gapotchenko.FX.Diagnostics;
foreach (var process in Process.GetProcessesByName("notepad"))
{
var result = process.End();
Console.WriteLine(result);
}
Once there is a running Notepad app, the sample produces the following output:
Close
signifying that a Notepad process was gracefully ended by closing its main window.
Now let's repeat the experiment by launching a Notepad app again and opening its "File Save" dialog via menu (File → Save As...). This time, let's keep the "File Save" dialog open, and launch the example code once again.
This time the result will be different:
Kill
The Notepad process was unable to shutdown gracefully and thus was forcefully killed. Graceful shutdown was not possible because the process had an active modal dialog.
<details> <summary>More examples</summary>
Let's modify sample a bit:
foreach (var process in Process.GetProcessesByName("notepad"))
{
var result = process.End();
Console.WriteLine("PID {0}", process.Id);
Console.WriteLine("Graceful: {0}", (result & ProcessEndMode.Graceful) != 0);
Console.WriteLine("Forceful: {0}", (result & ProcessEndMode.Forceful) != 0);
}
Now it shows the Id of a process that was ended together with a graceful/forceful classification of the result.
What if we want to limit the End() method to only perform a graceful process termination?
Let's use the End(ProcessEndMode) method overload:
foreach (var process in Process.GetProcessesByName("notepad"))
{
var result = process.End(ProcessEndMode.Graceful);
Console.WriteLine("PID {0}", process.Id);
Console.WriteLine(result);
}
Now the result will only be graceful, or have ProcessEndMode.None value if a process could not be gracefully ended.
But what if we want to limit the End() method to only perform a graceful process termination via Ctrl+C (SIGINT) signal and forceful kill?
No problem:
foreach (var process in Process.GetProcessesByName("notepad"))
{
var result = process.End(ProcessEndMode.Interrupt | ProcessEndMode.Kill);
Console.WriteLine("PID {0}", process.Id);
Console.WriteLine(result);
}
As you can see, despite a simple-looking signature, the End(…) method gives enormous possibilities for achieving a specific goal.
</details>
The method is similar to End() but has an async implementation.
It can be used to efficiently handle dozens of processes in a bulk.
For example, there is a need to shut down quite a few processes, say 20. One possible solution is to shut down the processes sequentially, one by one. But this may take quite a few moments to complete, up to several dozen seconds. On a positive side, it only takes one CPU thread. The second solution is to shut down the processes in parallel. This solution will reduce the overall time significantly, but that reduction will come at the expense of 20 wasted CPU threads. What if we could have the benefits of both solutions at the same time?
We can achieve that by using asynchronous code, like so:
static Task<ProcessEndMode[]> EndProcessesAsync(IEnumerable<Process> processesToEnd) =>
Task.WhenAll(processesToEnd.Select(x => x.EndAsync()));
Even if you write a single-threaded app, you still get the benefits of asynchronous code here: the processes are shut down in parallel and no CPU threads are wasted.
Here is a full example that demonstrates that:
using Gapotchenko.FX.Diagnostics;
using Gapotchenko.FX.Threading.Tasks;
using System.Diagnostics;
class Program
{
static void Main()
{
var processEndModes = TaskBridge.Execute(
EndProcessesAsync(
Process.GetProcessesByName("notepad"));
Console.WriteLine(
"Notepads were ended with the following results: {0}.",
string.Join(", ", processEndModes.Select(x => x.ToString())));
}
static Task<ProcessEndMode[]> EndProcessesAsync(IEnumerable<Process> processesToEnd) =>
Task.WhenAll(processesToEnd.Select(x => x.EndAsync()));
}
(Reminder: the correct way to wait for the completion of an asynchronous task in synchronous code is to use TaskBridge)
Let's continue with a look at some other modules provided by Gapotchenko.FX:
Or look at the full list of modules.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 was computed. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net6.0-windows7.0 net6.0-windows7.0 is compatible. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net7.0-windows7.0 net7.0-windows7.0 is compatible. net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net8.0-windows7.0 net8.0-windows7.0 is compatible. net9.0 net9.0 is compatible. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net9.0-windows7.0 net9.0-windows7.0 is compatible. net10.0 net10.0 is compatible. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. net10.0-windows7.0 net10.0-windows7.0 is compatible. |
| .NET Core | netcoreapp2.0 netcoreapp2.0 was computed. netcoreapp2.1 netcoreapp2.1 was computed. netcoreapp2.2 netcoreapp2.2 was computed. netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 netstandard2.0 is compatible. netstandard2.1 netstandard2.1 is compatible. |
| .NET Framework | net461 net461 was computed. net462 net462 was computed. net463 net463 was computed. net47 net47 was computed. net471 net471 was computed. net472 net472 is compatible. net48 net48 was computed. net481 net481 was computed. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen40 tizen40 was computed. tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
Showing the top 5 NuGet packages that depend on Gapotchenko.FX.Diagnostics.Process:
| Package | Downloads |
|---|---|
|
IoFluently.NetStandard
Package Description |
|
|
Gapotchenko.FX.Profiles.Core
Represents the Core profile of Gapotchenko.FX toolkit. |
|
|
Gapotchenko.FX.Console
Provides virtual terminal functionality, console traits, and other useful primitives for .NET console apps. |
|
|
Gapotchenko.FX.AppModel.Information
Provides functionality for getting information about the app. |
|
|
BlossomiShymae.GrrrLCU
A simple wrapper for the LCU. Grrr. x3 |
Showing the top 2 popular GitHub repositories that depend on Gapotchenko.FX.Diagnostics.Process:
| Repository | Stars |
|---|---|
|
blish-hud/Blish-HUD
A Guild Wars 2 overlay with extreme extensibility through compiled modules.
|
|
|
Dyvinia/FrostyFix
A tool to fix Frosty Support with games on platforms other than Origin (EA Desktop, Epic Games Store, Steam)
|
| Version | Downloads | Last Updated |
|---|---|---|
| 2026.7.2 | 2,623 | 5/16/2026 |
| 2026.6.2 | 5,718 | 3/29/2026 |
| 2026.5.3 | 1,639 | 2/24/2026 |
| 2026.4.2 | 389 | 2/4/2026 |
| 2026.3.5 | 318 | 1/29/2026 |
| 2026.2.2 | 3,609 | 1/25/2026 |
| 2026.1.5 | 292 | 1/13/2026 |
| 2025.1.45 | 2,893 | 12/25/2025 |
| 2025.1.27-beta | 370 | 10/8/2025 |
| 2025.1.26-beta | 404 | 8/30/2025 |
| 2025.1.25-beta | 1,124 | 7/22/2025 |
| 2025.1.24-beta | 549 | 7/16/2025 |
| 2025.1.23-beta | 405 | 7/12/2025 |
| 2024.2.5 | 25,337 | 12/31/2024 |
| 2024.1.3 | 5,286 | 11/10/2024 |
| 2022.2.7 | 68,964 | 5/1/2022 |
| 2022.2.5 | 1,769 | 5/1/2022 |
| 2022.1.4 | 1,782 | 4/6/2022 |
| 2021.2.21 | 2,031 | 1/21/2022 |