SelectQuery 占用 100% CPU
我正在对计算机上的所有用户进行查询,当它执行时,它会占用 100% 的 CPU 并锁定系统。我已经等了 5 分钟,但什么也没发生。
在任务管理器中,wmiprvse.exe 正在使用所有 CPU。当我杀死该进程时,一切都会恢复正常。
这是我的代码:
SelectQuery query = new SelectQuery("Win32_UserAccount",
"LocalAccount=1 and Domain='" + GetMachine().DomainName + "'");
using(ManagementObjectSearcher searcher = new ManagementObjectSearcher(query)) {
IList<WindowsUser> users = new List<WindowsUser>();
Console.WriteLine("Getting users...");
foreach (ManagementObject envVar in searcher.Get()) {
Console.WriteLine("Getting " + envVar["Name"].ToString() + "...");
}
}
在控制台中我看到的只是获取用户......没有其他任何东西。问题似乎出在 searcher.Get() 上。
有谁知道为什么这个查询占用 100% CPU?谢谢。
编辑:好的,我发现 WMI 进程只占用 25% 的 CPU,但如果我结束程序(查询永远不会完成),它不会被释放。下次我启动一个实例时,该进程的 CPU 利用率会上升到 50%,依此类推,直到达到 100%。
所以我的新问题是为什么 CPU 没有被释放以及这样的查询需要多长时间才能完成?
I am doing a query for all the users on the machine and when it executes it grabs 100% CPU and locks up the system. I have waited up to 5 minutes and nothing happens.
In the Task Manager wmiprvse.exe is using all the CPU. When I kill that process everything returns to normal.
Here is my code:
SelectQuery query = new SelectQuery("Win32_UserAccount",
"LocalAccount=1 and Domain='" + GetMachine().DomainName + "'");
using(ManagementObjectSearcher searcher = new ManagementObjectSearcher(query)) {
IList<WindowsUser> users = new List<WindowsUser>();
Console.WriteLine("Getting users...");
foreach (ManagementObject envVar in searcher.Get()) {
Console.WriteLine("Getting " + envVar["Name"].ToString() + "...");
}
}
In the console all I see is Getting users... and nothing else. The problem appears to be with searcher.Get().
Does anyone know why this query is taking 100% CPU? Thanks.
EDIT: OK I found that it the WMI process is only eating 25% CPU but it doesn't get released if I end the program (the query never finishes). The next time I start an instance the process goes up to 50% CPU, etc, etc until it is at 100%.
So my new question is why is the CPU not getting released and how long should a query like this take to complete?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个
Try this