private void cmdSample_Click(object sender, EventArgs e) { try { PerfCounterCollectorEntry currentEntry = null; if (optCommon.Checked) { currentEntry = PerfCounterCollectorEntry.FromStringDefinition(txtComputerName.Text + "\\" + cboPerformanceCounter.Text); } else { currentEntry = PerfCounterCollectorEntry.FromStringDefinition(txtPerfCounter.Text); } if (currentEntry == null || currentEntry.Computer.Length == 0) { MessageBox.Show("Performance counter definition could not be created!", "Definition", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { float val = currentEntry.GetNextValue(); Clipboard.SetText(val.ToString("F4")); MessageBox.Show(string.Format("Current value: {0}", val.ToString("F4")), "Test", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Test", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void cmdSample_Click(object sender, EventArgs e) { try { if (currentEntry != null) { float val = currentEntry.GetNextValue(); Clipboard.SetText(val.ToString("F4")); MessageBox.Show(string.Format("Current value: {0}", val.ToString("F4")), "Test", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Test", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public override void RefreshDisplayData() { Cursor.Current = Cursors.WaitCursor; try { lvwEntries.BeginUpdate(); foreach (ListViewItem lvi in lvwEntries.Items) { try { PerfCounterCollectorEntry pc = (PerfCounterCollectorEntry)lvi.Tag; float currentValue = pc.GetNextValue(); lvi.SubItems[1].Text = currentValue.ToString("F3"); CollectorState currentState = pc.GetState(currentValue); if (currentState == CollectorState.Good) { lvi.ImageIndex = 0; lvi.BackColor = SystemColors.Window; } else if (currentState == CollectorState.Warning) { lvi.ImageIndex = 1; lvi.BackColor = Color.SandyBrown; } else { lvi.ImageIndex = 2; lvi.BackColor = Color.Salmon; } } catch (Exception ex) { lvi.SubItems[1].Text = ex.Message; } } toolStripStatusLabelDetails.Text = "Last updated: " + DateTime.Now.ToString("yyyy-mm-dd HH:mm:ss"); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } lvwEntries.EndUpdate(); Cursor.Current = Cursors.Default; }