public PerformanceCountersGroup(string groupName, bool bEnabled, TreeView parentTreeView, PerformanceCountersGroupsType groupType, PerformanceCounterType[] counterTypes, int targetProcessID) { Debug.Assert(!(groupType == PerformanceCountersGroupsType.Custom && counterTypes != null), "Pre-defined PerformanceCounterTypes cannot be used with a custom PerformanceCountersGroupsType"); _groupType = groupType; _groupName = groupName; _enabled = bEnabled; System.Diagnostics.Process targetProcess = null; bool bCreateGroup = true; // first find our target process if (targetProcessID != 0) { System.Diagnostics.Process[] processlist = System.Diagnostics.Process.GetProcesses(); foreach (System.Diagnostics.Process proc in processlist) { if (proc.Id == targetProcessID) { targetProcess = proc; break; } } if (targetProcess != null) { _groupName += string.Format("({0}.exe)", targetProcess.ProcessName); } else { bCreateGroup = false; _enabled = false; } } if (bCreateGroup) { _treeViewItem = new TreeViewItem(); StackPanel stackPanel = new StackPanel(); _treeViewItem.Header = stackPanel; stackPanel.Orientation = Orientation.Horizontal; _checkBox = new CheckBox(); _checkBox.IsChecked = _enabled = bEnabled; stackPanel.Children.Add(_checkBox); TextBlock textBlock = new TextBlock() { Text = _groupName }; stackPanel.Children.Add(textBlock); if (counterTypes != null) { for (int i = 0; i < counterTypes.Length; ++i) { BasicPerformanceCounter newCounter = CreatePerformanceCounter(counterTypes[i]); newCounter.Initialize(targetProcess); _treeViewItem.Items.Add(newCounter._treeViewItem); } } parentTreeView.Items.Add(_treeViewItem); _initialized = true; } }
public PerformanceCountersGroup CreateNewGroup(string groupName, bool bEnabled, TreeView parentTreeView, PerformanceCountersGroupsType groupType = PerformanceCountersGroupsType.Custom, PerformanceCountersGroup.PerformanceCounterType[] counterTypes = null, int targetProcessID = 0) { Debug.Assert(!(groupType == PerformanceCountersGroupsType.Custom && counterTypes != null), "Pre-defined PerformanceCounterTypes cannot be used with a custom PerformanceCountersGroupsType"); PerformanceCountersGroup newGroup = new PerformanceCountersGroup(groupName, bEnabled, parentTreeView, groupType, counterTypes, targetProcessID); _performanceCountersGroups.Add(newGroup); return(newGroup); }
public PerformanceCountersGroup CreateNewGroup(string groupName, bool bEnabled, TreeView parentTreeView, PerformanceCountersGroupsType groupType = PerformanceCountersGroupsType.Custom, PerformanceCountersGroup.PerformanceCounterType[] counterTypes = null, int targetProcessID = 0) { Debug.Assert(!(groupType == PerformanceCountersGroupsType.Custom && counterTypes != null), "Pre-defined PerformanceCounterTypes cannot be used with a custom PerformanceCountersGroupsType"); PerformanceCountersGroup newGroup = new PerformanceCountersGroup(groupName, bEnabled, parentTreeView, groupType, counterTypes, targetProcessID); _performanceCountersGroups.Add(newGroup); return newGroup; }
public PerformanceCountersGroup(string groupName, bool bEnabled, TreeView parentTreeView, PerformanceCountersGroupsType groupType, PerformanceCounterType[] counterTypes, int targetProcessID) { Debug.Assert(!(groupType == PerformanceCountersGroupsType.Custom && counterTypes != null), "Pre-defined PerformanceCounterTypes cannot be used with a custom PerformanceCountersGroupsType"); _groupType = groupType; _groupName = groupName; _enabled = bEnabled; System.Diagnostics.Process targetProcess = null; bool bCreateGroup = true; // first find our target process if (targetProcessID != 0) { System.Diagnostics.Process[] processlist = System.Diagnostics.Process.GetProcesses(); foreach (System.Diagnostics.Process proc in processlist) { if (proc.Id == targetProcessID) { targetProcess = proc; break; } } if (targetProcess != null) { _groupName += string.Format("({0}.exe)", targetProcess.ProcessName); } else { bCreateGroup = false; _enabled = false; } } if (bCreateGroup) { _treeViewItem = new TreeViewItem(); StackPanel stackPanel = new StackPanel(); _treeViewItem.Header = stackPanel; _treeViewItem.Foreground = VisualStyle.Foreground; stackPanel.Orientation = Orientation.Horizontal; _checkBox = new CheckBox(); _checkBox.IsChecked = _enabled = bEnabled; stackPanel.Children.Add(_checkBox); TextBlock textBlock = new TextBlock() { Text = _groupName }; stackPanel.Children.Add(textBlock); if (counterTypes != null) { for (int i = 0; i < counterTypes.Length; ++i) { BasicPerformanceCounter newCounter = CreatePerformanceCounter(counterTypes[i]); newCounter.Initialize(targetProcess); _treeViewItem.Items.Add(newCounter._treeViewItem); } } parentTreeView.Items.Add(_treeViewItem); _initialized = true; } }