PerformanceCounter in .net
VB.NET:
Imports System.Diagnostics
Imports System.Timers
Module 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 Sub
Sub 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 Sub
End Module
Imports System.Timers
Module 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 Sub
Sub 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 Sub
End 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();
}
}
}
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();
}
}
}