我在我的 c# 应用程序 backgroundworker 和 dowork 无限循环中有,但 backgroundworker 的 cpu 使用率非常大(50%)。如何限制backgroundworker的cpu使用?
代码:
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();
}
}
}
}