我寫了一個服務,該服務運行一個線程,每分鐘設置一次設置。命名管道在服務中導致CPU使用率高
該服務做它應該做的事情,但後來發現它使CPU使用率變得非常高(在雙核上約爲25%)。
使用試驗和錯誤,我發現以下對象正在導致問題:
private AsyncPipes.NamedPipeStreamServer pipeServer = new NamedPipeStreamServer("NotifyToService");
private AsyncPipes.NamedPipeStreamClient pipeClient = new NamedPipeStreamClient("ServiceToNotify");
這是正常的命名管道使用如此多的CPU,只是被實例化?
可能需要顯示您的代碼。 –
您可能想要使用睡眠間隔。看到這個例子: http://stackoverflow.com/questions/17150856/windows-service-not-executing-after-first-run/17151266#17151266 – jor
你有沒有觀察到如果你運行另一個CPU密集型的程序會發生什麼好? – rro