using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading;using System.Timers;using System.Runtime.InteropServices;namespace Imba_Timer{ class Program { public Thread[] tCountHF; public Thread tCountLF; public static int timeHF = 0; public static int timeLF = 0; [DllImport("Kernel32.dll")] private static extern bool QueryPerformanceCounter( out long lpPerformanceCount); [DllImport("Kernel32.dll")] private static extern bool QueryPerformanceFrequency( out long lpFrequency); Program() { tCountLF = new Thread(ShowTime); } Program(int numThreads) { tCountHF = new Thread[numThreads]; for (int i = 0; i < numThreads; i++) { tCountHF = new Thread(SleepOne); } } static void Main(string[] args) { Program myPrg = new Program(); myPrg.ThreadsStartup(250); Console.ReadLine(); } public void StartUpCounter(int microSeconds) { float stepTimeSec = (float)1 * (float)(microSeconds / 1000000) ; int x = 100; float secondsPerOpp = 0; float secondsPerOpp2 = 0; float incrTime = 0; long cntsPerSec = 0; long prevTimeStamp = 0; long currTimeStamp = 0; long prevTimeStamp2 = 0; long currTimeStamp2 = 0; QueryPerformanceFrequency(out cntsPerSec); do { QueryPerformanceCounter(out prevTimeStamp2); QueryPerformanceCounter(out prevTimeStamp); while (x > 0) { x--; } x = 100; QueryPerformanceCounter(out currTimeStamp); secondsPerOpp = (currTimeStamp - prevTimeStamp) * (1.0f / (float)cntsPerSec); QueryPerformanceCounter(out currTimeStamp2); secondsPerOpp2 = (currTimeStamp2 - prevTimeStamp2) * (1.0f / (float)cntsPerSec); incrTime += (secondsPerOpp + secondsPerOpp2); } while (incrTime < stepTimeSec); } public void ThreadsStartup(int microSec) { int numThreads = 1000 / microSec; Program start = new Program(numThreads); Program lowFrequency = new Program(); lowFrequency.tCountLF.Start(); for (int i = 0; i < numThreads; i++) { start.tCountHF.Priority = ThreadPriority.Highest; start.tCountHF.Start(this); start.StartUpCounter(microSec); } } public void SleepOne(object obj) { //while (!stop) for (int g = 0; g < 120000; g++) { Thread.Sleep(1); timeHF++; } } public void ShowTime() { //while (!stop); for (int g = 0; g < 120; g++) { Thread.Sleep(1000); timeLF += 1000; Console.WriteLine("Hight Frequency Time is: " + timeHF + " ------ " + "Low Frequency Time is: " + timeLF); } } }}
For now this code is not very useful since most of these high frequency timings are used in something other than games where you can use the Sleep() function. Plus it is not very precise which I do not know why. Oh well was worth a shot.