wasSharpNET – Blame information for rev 27

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 ///////////////////////////////////////////////////////////////////////////
2 // Copyright (C) Wizardry and Steamworks 2016 - License: GNU GPLv3 //
3 // Please see: http://www.gnu.org/licenses/gpl.html for legal details, //
4 // rights of fair usage, the disclaimer and warranty conditions. //
5 ///////////////////////////////////////////////////////////////////////////
6  
7 using System.Diagnostics;
8  
9 namespace wasSharpNET
10 {
11 public static class Process
12 {
13 /// <summary>
14 /// Retrieves the instance name from a processr.
15 /// </summary>
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>
18 /// <remarks>(C) Ingo Rammer</remarks>
19 public static string GetProcessInstanceName(this System.Diagnostics.Process proc)
20 {
21 var cat = new PerformanceCounterCategory("Process");
3 office 22  
1 office 23 foreach (var instance in cat.GetInstanceNames())
24 using (var cnt = new PerformanceCounter("Process", "ID Process", instance, true))
25 {
27 office 26 var val = (int) cnt.RawValue;
1 office 27 if (val == proc.Id)
28 return instance;
29 }
30 return null;
31 }
32 }
27 office 33 }