- Main Page
- Classes
- Files

- File List

# C:/Users/Andreas Schiffler/Desktop/SVN/NewGamePhysics/NewGamePhysics/Utilities/HighResolutionTimer.cs

    00001 ﻿//-----------------------------------------------------------------------------
    00002 // HighResolutionTimer.cs
    00003 // (A. Schiffler, 2009)
    00004 //-----------------------------------------------------------------------------
    00005
    00006 namespace NewGamePhysics.Utilities
    00007 {
    00008     using System;
    00009     using System.ComponentModel;
    00010     using System.Runtime.InteropServices;
    00011     using System.Threading;
    00012
    00017     public class HighResolutionTimer
    00018     {
    00024         [DllImport("Kernel32.dll")]
    00025         private static extern bool QueryPerformanceCounter(
    00026             out long lpCounter);
    00027
    00033         [DllImport("Kernel32.dll")]
    00034         private static extern bool QueryPerformanceFrequency(
    00035             out long lpFrequency);
    00036
    00041         public static long Counter()
    00042         {
    00043             long counter;
    00044
    00045             if (!QueryPerformanceCounter(out counter))
    00046             {
    00047                 throw new Win32Exception("Error calling QueryPerformanceCounter()");
    00048             }
    00049
    00050             return counter;
    00051         }
    00052
    00057         public static long Frequency()
    00058         {
    00059             long frequency;
    00060
    00061             if (!QueryPerformanceFrequency(out frequency))
    00062             {
    00063                 throw new Win32Exception("Error calling QueryPerformanceFrequency()");
    00064             }
    00065
    00066             return frequency;
    00067         }
    00068
    00073         public static double Seconds()
    00074         {
    00075             return (double)Counter() / (double)Frequency();
    00076         }
    00077     }
    00078 }