I would recommend OS functionality. Windows has performance counters and WinAPI features.
Here is an example of using performance counters from the BCL Blog :
foreach (Process proc in Process.GetProcesses()) { using (PerformanceCounter pcProcess = new PerformanceCounter("Process", "% Processor Time", proc.ProcessName)) { pcProcess.NextValue(); System.Threading.Thread.Sleep(1000); Console.WriteLine("Process:{0} CPU% {1}", proc.ProcessName, pcProcess.NextValue()); } }
This code does the same with WMI from CodeProject :
public string GetCPU() { decimal PercentProcessorTime=0; mObject_CPU.Get(); ulong u_newCPU = (ulong)mObject_CPU.Properties["PercentProcessorTime"].Value; ulong u_newNano = (ulong)mObject_CPU.Properties["TimeStamp_Sys100NS"].Value; decimal d_newCPU = Convert.ToDecimal(u_newCPU); decimal d_newNano = Convert.ToDecimal(u_newNano); decimal d_oldCPU = Convert.ToDecimal(u_oldCPU); decimal d_oldNano = Convert.ToDecimal(u_oldNano);
Thus, you can request these OS providers (or others for your OS) and sleep flow if the processor load is high.
source share