私は機能を定期的にスキャンする必要がありますプロセスリストを実行するスキャンを再開する例外を終了するプロセスを再起動します。Process.GetProcesses()パフォーマンスの問題を使用して長時間実行しているオペレーティングシステムで
私はProcess.GetProcesses()
を使用して、現在実行中のプロセスのリストを取得します。ほとんどのコンピュータではパフォーマンスの問題はありません。
しかし、処理時間が最大100ミリ秒のProcess.GetProcesses()
を使用し、処理時間が通常のProcess.GetProcesses()
になっていて、長時間実行しているサーバー(147日間稼働していて、新しいPIDが100万であった)数ミリ秒。これはシステムのパフォーマンスに影響します。
ProcessesProtectionThread = new Thread(() => {
try {
while (true) {
try {
//I use the Stopwatch, and I found that almost always deal with this line
// of code.
var currentProcesses = Process.GetProcesses();
var protectedProcesses = currentProcesses.Where(item => protectProcessesNames.Contains(item.ProcessName.ToUpper()));
var protectedProcessesPaths = protectedProcesses.Select(item => item?.MainModule?.FileName?.ToUpper()).Distinct().ToList();
var restartProcessesPaths = protectProcessesPaths.Where(item => !protectedProcessesPaths.Contains(item)).ToList();
RestartProcess(restartProcessesPaths, currentProcesses);
}
catch (ThreadAbortException) { }
catch (Exception ex) { LogHelper.WriteExMessage(ex); }
finally { Thread.Sleep(ProcessProtectionInterval); }
}
}
catch (ThreadAbortException) { }
catch (Exception ex) { LogHelper.WriteExMessage(ex); }
});
ProcessesProtectionThread.IsBackground = true;
ProcessesProtectionThread.Start();
この問題の解決方法を教えてもらえますか?
「Process.GetProcesses()」を1秒間に何回呼び出していますか? – MickyD
@MickyDこれは設定可能です(通常1秒に1回)。しかし、私は別の操作をしながら同時に複数のスレッドを実行する必要があります。 – Tim
おそらくコードの一部を投稿しますか? – MickyD