TechEd follow up...
Thanks to all those who attended my sessions at TechEd. As promised in my SQL Mobile session here is the source for a very simpler timer class to help you monitor performance.
using
System;
using
System.Collections.Generic;
using
System.Windows.Forms;
using
System.Runtime.InteropServices;
namespace
Timer
{
public class TestTimer
{
[
DllImport("CoreDll.dll")]
public static extern int QueryPerformanceFrequency
(
ref Int64 lpFrequency
);
[
DllImport("CoreDll.dll")]
public static extern int QueryPerformanceCounter
(
ref Int64 lpPerformanceCount
);
System.
Int64 freq = 0;
public TestTimer()
{
QueryPerformanceFrequency(
ref freq);
}
public delegate void timerResult(string msg,System.Int64 time);
public event timerResult OnTimerResult;
private System.Int64 _startTime = 0 ;
private System.Int64 _lastReading = 0;
public bool TimerSupported
{
get
{
bool result = true;
if (QueryPerformanceFrequency(ref freq) == 0)
result =
false;
System.
Int64 testCounter = 0;
if (QueryPerformanceCounter(ref testCounter) == 0)
result =
false;
return (result);
}
}
public void Start()
{
QueryPerformanceCounter(
ref _startTime);
_lastReading = _startTime;
}
public void TakeReading(string msg)
{
System.
Int64 _takeReading = 0;
QueryPerformanceCounter(
ref _takeReading);
System.
Int64 time_ms = (_takeReading - _lastReading) * 1000 / freq;
_lastReading = _takeReading;
if (OnTimerResult!=null)
OnTimerResult(msg,time_ms);
}
public void TotalTime(string msg)
{
_lastReading = _startTime;
TakeReading(msg);
}
}
}