Windows 2008R2 上的 WMI 请求缓慢
有没有人对加快 WMI 查询有任何建议?我每 5 秒更新一次客户端应用程序以显示 CPU 统计信息。在 Windows 2003 上速度要快得多,但至少需要 5 秒才能返回 4 个 CPU 核心的整数:
Private Sub GetProcessorIdleTime(ByVal Server As String)
Dim searcher As New ManagementObjectSearcher("\\" & Server & "\root\CIMV2", "SELECT LoadPercentage FROM Win32_Processor")
Dim collection As ManagementObjectCollection = searcher.[Get]()
For Each row In collection
TextBox1.Text = TextBox1.Text & vbCrLf & Convert.ToInt32(row("LoadPercentage"))
Next
End Sub
或者是否有更好的方法来远程检索此信息?
Has anyone got any suggestions to speed up this WMI query? I'm updating a client application every 5 seconds to show the CPU stats. It was much quicker on Windows 2003 but takes at least 5 seconds to return an integer for 4 CPU cores:
Private Sub GetProcessorIdleTime(ByVal Server As String)
Dim searcher As New ManagementObjectSearcher("\\" & Server & "\root\CIMV2", "SELECT LoadPercentage FROM Win32_Processor")
Dim collection As ManagementObjectCollection = searcher.[Get]()
For Each row In collection
TextBox1.Text = TextBox1.Text & vbCrLf & Convert.ToInt32(row("LoadPercentage"))
Next
End Sub
Or is there a better way to retrive this information remotely?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为了提高性能,您必须重新使用与远程服务器的 WMI 连接,建立连接是执行 WQL 语句时最昂贵的任务之一。
在您的代码中,您每次都设置一个新的 WMI 远程连接。因此,请重写您的代码,创建一个新方法来建立远程连接,然后在 GetProcessorIdleTime 方法中重用(共享)
ManagementObjectSearcher
对象。To improve the performance, you must re-use the WMI connection to the remote server, establishing a connection is one of the more expensive tasks when you execute a WQL sentence.
In your code you are setting a new WMI remote connection each time. So rewrite your code creating a new method to establish the remote connection and then reuse (share) the
ManagementObjectSearcher
object in your GetProcessorIdleTime method.