- public class T_DebugPerformanceCounter
- {
- [System.Runtime.InteropServices.DllImport("Kernel32.dll")]
- static extern bool QueryPerformanceCounter(ref long count);
-
- [System.Runtime.InteropServices.DllImport("Kernel32.dll")]
- static extern bool QueryPerformanceFrequency(ref long count);
-
- public static T_DebugPerformanceCounter FactoryTimer()
- {
- if (_MeTimer == null)
- {
- _MeTimer = new T_DebugPerformanceCounter();
- }
- return _MeTimer;
- }
-
-
- private static long _Frequency;
- private long _StartCount;
- private T_DebugPerformanceCounter()
- {
- QueryPerformanceFrequency(ref _Frequency);
-
- }
- private static T_DebugPerformanceCounter _MeTimer;
- public void StartCount()
- {
- QueryPerformanceCounter(ref _StartCount);
- }
-
- public void PerformCount(string info)
- {
- long count1 = 0;
- double result = 0;
-
- QueryPerformanceCounter(ref count1);
- long p = count1 - _StartCount;
- result = (double)(p) / (double)_Frequency*1000;
- UtiltyObj.WriteExceptionToLog(string.Format(info + "耗时: {0} 毫 秒", result), System.Diagnostics.EventLogEntryType.SuccessAudit , EventLevel.运行 );
- }
- }