wasSharpNET – Diff between revs 3 and 11
?pathlinks?
Rev 3 | Rev 11 | |||
---|---|---|---|---|
1 | /////////////////////////////////////////////////////////////////////////// |
1 | /////////////////////////////////////////////////////////////////////////// |
|
2 | // Copyright (C) Wizardry and Steamworks 2016 - License: GNU GPLv3 // |
2 | // Copyright (C) Wizardry and Steamworks 2016 - License: GNU GPLv3 // |
|
3 | // Please see: http://www.gnu.org/licenses/gpl.html for legal details, // |
3 | // Please see: http://www.gnu.org/licenses/gpl.html for legal details, // |
|
4 | // rights of fair usage, the disclaimer and warranty conditions. // |
4 | // rights of fair usage, the disclaimer and warranty conditions. // |
|
5 | /////////////////////////////////////////////////////////////////////////// |
5 | /////////////////////////////////////////////////////////////////////////// |
|
6 | |
6 | |
|
7 | using System.Diagnostics; |
7 | using System.Diagnostics; |
|
8 | |
8 | |
|
9 | namespace wasSharpNET |
9 | namespace wasSharpNET |
|
10 | { |
10 | { |
|
11 | public static class Process |
11 | public static class Process |
|
12 | { |
12 | { |
|
13 | /// <summary> |
13 | /// <summary> |
|
14 | /// Retrieves the instance name from a processr. |
14 | /// Retrieves the instance name from a processr. |
|
15 | /// </summary> |
15 | /// </summary> |
|
16 | /// <param name="proc">the process</param> |
16 | /// <param name="proc">the process</param> |
|
17 | /// <returns>the instance name of a process or null if the instance name was not found</returns> |
17 | /// <returns>the instance name of a process or null if the instance name was not found</returns> |
|
18 | /// <remarks>(C) Ingo Rammer</remarks> |
18 | /// <remarks>(C) Ingo Rammer</remarks> |
|
19 | public static string GetProcessInstanceName(this System.Diagnostics.Process proc) |
19 | public static string GetProcessInstanceName(this System.Diagnostics.Process proc) |
|
20 | { |
20 | { |
|
21 | var cat = new PerformanceCounterCategory("Process"); |
21 | var cat = new PerformanceCounterCategory("Process"); |
|
22 | |
22 | |
|
23 | foreach (var instance in cat.GetInstanceNames()) |
23 | foreach (var instance in cat.GetInstanceNames()) |
|
24 | { |
24 | { |
|
25 | using (var cnt = new PerformanceCounter("Process", "ID Process", instance, true)) |
25 | using (var cnt = new PerformanceCounter("Process", "ID Process", instance, true)) |
|
26 | { |
26 | { |
|
27 | var val = (int) cnt.RawValue; |
27 | var val = (int)cnt.RawValue; |
|
28 | if (val == proc.Id) |
28 | if (val == proc.Id) |
|
29 | { |
29 | { |
|
30 | return instance; |
30 | return instance; |
|
31 | } |
31 | } |
|
32 | } |
32 | } |
|
33 | } |
33 | } |
|
34 | return null; |
34 | return null; |
|
35 | } |
35 | } |
|
36 | } |
36 | } |
|
37 | } |
- | ||
38 | |
37 | } |
|
- | 38 | |
||
39 |
|
- | ||
40 | |
- | ||
41 | |
- | ||
42 | |
- |