



















VB.NET:
Imports System.Diagnostics
Imports System.TimersModule Module1
Private HeapCounter As PerformanceCounter = Nothing
Private ExceptionCounter As PerformanceCounter = Nothing
Private timer As Timer = New Timer(3000)Private Sub OnTick(ByVal source As Object, ByVal e As ElapsedEventArgs)End SubSub Main()
AddHandler timer.Elapsed, AddressOf OnTick
timer.Enabled = True
Dim HeapCounter As New PerformanceCounter(".NET CLR Memory", "# Bytes in all Heaps")
HeapCounter.InstanceName = "_Global_"
Dim ExceptionCounter As New PerformanceCounter(".Net CLR Exceptions", "# of Exceps Thrown")
ExceptionCounter.InstanceName = "_Global_"
Console.WriteLine("Press [Enter] to Quit Program")
Console.WriteLine("# of Bytes in all Heaps : " + HeapCounter.NextValue().ToString())
Console.WriteLine("# of Exceptions Thrown: " + ExceptionCounter.NextValue().ToString())
Console.ReadLine()
End SubEnd Module
C#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Timers;namespace PerformanceCounterCS
{
class Program
{
private static PerformanceCounter HeapCounter = null;
private static PerformanceCounter ExceptionCounter = null;
private static Timer timer = new Timer(3000);private static void OnTick(object source, ElapsedEventArgs e)
{
}static void Main(string[] args)
{
timer.Elapsed += new ElapsedEventHandler(OnTick);
timer.Enabled = true;
HeapCounter = new PerformanceCounter(".NET CLR Memory", "# Bytes in all Heaps");
HeapCounter.InstanceName = "_Global_";
ExceptionCounter = new PerformanceCounter(".Net CLR Exceptions", "# of Exceps Thrown");
ExceptionCounter.InstanceName = "_Global_";
Console.WriteLine("Press [Enter] to Quit Program");
Console.WriteLine("# of Bytes in all Heaps : " + HeapCounter.NextValue().ToString());
Console.WriteLine("# of Exceptions Thrown: " + ExceptionCounter.NextValue().ToString());
Console.ReadLine();
}
}
}
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。