728x90
반응형
728x170
▶ PerformanceCounter 클래스 : 프로세스명으로 인스턴스명 딕셔너리 구하기 예제
using System;
using System.Collections.Generic;
Dictionary<int, string> dictionary = GetInstanceNameDictionary("notepad");
foreach(KeyValuePair<int, string> keyValuePair in dictionary)
{
int processID = keyValuePair.Key;
string instanceName = keyValuePair.Value;
Console.WriteLine("프로세스 ID : {0}, 인스턴스명 : {1}", processID, instanceName);
}
728x90
▶ PerformanceCounter 클래스 : 프로세스명으로 인스턴스명 딕셔너리 구하기
using System.Collections.Generic;
using System.Diagnostics;
#region 인스턴스명 딕셔너리 구하기 - GetInstanceNameDictionary(processName)
/// <summary>
/// 인스턴스명 딕셔너리 구하기
/// </summary>
/// <param name="processName">프로세스명</param>
/// <returns>인스턴스명 딕셔너리</returns>
public Dictionary<int, string> GetInstanceNameDictionary(string processName)
{
Dictionary<int, string> dictionary = new Dictionary<int, string>();
PerformanceCounterCategory category = new PerformanceCounterCategory("Process");
string[] instanceNameArray = category.GetInstanceNames();
foreach(string instanceName in instanceNameArray)
{
if(instanceName.StartsWith(processName))
{
using(PerformanceCounter counter = new PerformanceCounter("Process", "ID Process", instanceName, true))
{
int processID = (int)counter.RawValue;
dictionary.Add(processID, instanceName);
}
}
}
return dictionary;
}
#endregion
728x90
반응형
그리드형(광고전용)
'C# > Common' 카테고리의 다른 글
[C#/COMMON] IDataReader 인터페이스 : 레코드를 객체로 변환하기 (0) | 2019.09.20 |
---|---|
[C#/COMMON] PropertyInfo 클래스 : 타입의 속성 정보 배열 구하기 (0) | 2019.09.20 |
[C#/COMMON] 프로세스 CPU 사용률 제한하기 (0) | 2019.09.04 |
[C#/COMMON] 프로세스 CPU 사용률 제한하기 (0) | 2019.09.04 |
[C#/COMMON] PerformanceCounter 클래스 : 인스턴스명으로 프로세스 CPU 사용률 구하기 (0) | 2019.09.04 |
[C#/COMMON] PerformanceCounter 클래스 : 프로세스명으로 인스턴스명 딕셔너리 구하기 (0) | 2019.09.04 |
[C#/COMMON] Array 클래스 : Resize 정적 메소드를 사용해 배열 크기 변경하기 (0) | 2019.08.30 |
[C#/COMMON] Marshal 클래스 : 객체 직렬화/역직렬화하기 (0) | 2019.08.29 |
[C#/COMMON] Marshal 클래스 : 비관리 메모리 할당하기 (0) | 2019.08.29 |
[C#/COMMON] 리스트 데이터 지우기 (0) | 2019.08.27 |
[C#/COMMON] 강력한 형식의 어셈블리에서 서명되지 않은 어셈블리 참조 문제 해결하기 (0) | 2019.08.19 |
댓글을 달아 주세요