I have in my c# app backgroundworker and in dowork infinite loop but backgroundworker has very big cpu usage (50%). How to limit cpu usage of backgroundworker?
Code:
private void ScanWorker_DoWork(object sender, DoWorkEventArgs e)
{
BackgroundWorker worker = sender as BackgroundWorker;
while (!worker.CancellationPending)
{
Process[] Procesy = Process.GetProcesses();
foreach (Process Proces in Procesy)
{
List<BlaclistedProcess> blacklist = (from p in CurrentBlacklist.Processes
where p.ProcessName == Proces.ProcessName
select p).ToList<BlaclistedProcess>();
if (blacklist.Count == 1)
{
Proces.Kill();
}
}
}
}