wasSharpNET – Diff between revs 11 and 27
?pathlinks?
Rev 11 | Rev 27 | |||
---|---|---|---|---|
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 | { |
- | ||
25 | using (var cnt = new PerformanceCounter("Process", "ID Process", instance, true)) |
24 | using (var cnt = new PerformanceCounter("Process", "ID Process", instance, true)) |
|
26 | { |
25 | { |
|
27 | var val = (int)cnt.RawValue; |
26 | var val = (int) cnt.RawValue; |
|
28 | if (val == proc.Id) |
27 | if (val == proc.Id) |
|
29 | { |
- | ||
30 | return instance; |
28 | return instance; |
|
31 | } |
- | ||
32 | } |
29 | } |
|
33 | } |
- | ||
34 | return null; |
30 | return null; |
|
35 | } |
31 | } |
|
36 | } |
32 | } |
|
37 | } |
33 | } |
|
38 | |
34 | |
|
- | 35 |
|
||
- | 36 | |
||
- | 37 | |
||
- | 38 | |