コード例 #1
0
 private void LoadCategories(string machineName)
 {
     Cursor.Current = Cursors.WaitCursor;
     machineName    = ConfigVariables.ApplyOn(machineName);
     lvwCategories.Items.Clear();
     try
     {
         foreach (PerformanceCounterCategory performanceCounterCategory in (from p in PerformanceCounterCategory.GetCategories(machineName)
                                                                            orderby p.CategoryName
                                                                            select p))
         {
             ListViewItem lvi = new ListViewItem(performanceCounterCategory.CategoryName);
             if (InitialCategory != null && InitialCategory.Length > 0 && InitialCategory.ToLower() == performanceCounterCategory.CategoryName.ToLower())
             {
                 lvi.Selected = true;
             }
             lvwCategories.Items.Add(lvi);
         }
         if (lvwCategories.SelectedItems.Count == 0)
         {
             ListViewItem lviProc = (from ListViewItem lvi in lvwCategories.Items
                                     where lvi.Text == "Processor"
                                     select lvi).FirstOrDefault();
             if (lviProc != null)
             {
                 lviProc.Selected = true;
             }
         }
         if (lvwCategories.SelectedItems.Count > 0)
         {
             lvwCategories.SelectedItems[0].EnsureVisible();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     Cursor.Current = Cursors.Default;
 }
コード例 #2
0
ファイル: AddCounters.cs プロジェクト: supershowwei/qperfmon
        private void LoadCategories(string machineName)
        {
            Cursor.Current = Cursors.WaitCursor;
            lvwCategory.Items.Clear();
            try
            {
                List <ListViewItem> cats = new List <ListViewItem>();
                foreach (PerformanceCounterCategory performanceCounterCategory in (from c in PerformanceCounterCategory.GetCategories(machineName)
                                                                                   orderby c.CategoryName
                                                                                   select c))
                {
                    cats.Add(new ListViewItem(performanceCounterCategory.CategoryName));
                }
                lvwCategory.Items.AddRange(cats.ToArray());

                if (InitialCategory != null && InitialCategory.Length > 0)
                {
                    for (int i = 0; i < lvwCategory.Items.Count; i++)
                    {
                        if (InitialCategory.Length > 0 && lvwCategory.Items[i].Text.ToLower() == InitialCategory.ToLower())
                        {
                            lvwCategory.Items[i].Selected = true;
                            lvwCategory.Items[i].EnsureVisible();
                            break;
                        }
                    }
                }
                else
                {
                    for (int i = 0; i < lvwCategory.Items.Count; i++)
                    {
                        if (lvwCategory.Items[i].Text == "Processor")
                        {
                            lvwCategory.Items[i].Selected = true;
                            lvwCategory.Items[i].EnsureVisible();
                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            Cursor.Current = Cursors.Default;
        }
コード例 #3
0
 private void LoadCategories(string machineName)
 {
     Cursor.Current = Cursors.WaitCursor;
     cboCategory.Items.Clear();
     try
     {
         foreach (PerformanceCounterCategory performanceCounterCategory in PerformanceCounterCategory.GetCategories(machineName))
         {
             cboCategory.Items.Add(performanceCounterCategory.CategoryName);
         }
         if (InitialCategory != null && InitialCategory.Length > 0)
         {
             for (int i = 0; i < cboCategory.Items.Count; i++)
             {
                 if (InitialCategory.Length > 0 && cboCategory.Items[i].ToString().ToLower() == InitialCategory.ToLower())
                 {
                     cboCategory.SelectedIndex = i;
                     break;
                 }
             }
         }
         else
         {
             for (int i = 0; i < cboCategory.Items.Count; i++)
             {
                 if (cboCategory.Items[i].ToString() == "Processor")
                 {
                     cboCategory.SelectedIndex = i;
                     break;
                 }
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     Cursor.Current = Cursors.Default;
 }