I have a WMI request using ManagementObjectSearcher.
This usually works fine, but on some machines it hangs / does not return. I tried setting a timeout in the request, but it doesn't seem to matter.
This is my code:
using (var query = new ManagementObjectSearcher("SELECT IDProcess, PercentProcessorTime, WorkingSet FROM Win32_PerfFormattedData_PerfProc_Process")) { try { query.Options.Timeout = new TimeSpan(0, 0, 10); query.Options.ReturnImmediately = false; Log.Info("Query built"); foreach (ManagementObject obj in query.Get()) { using (obj) { var key = (uint)obj.GetPropertyValue("IDProcess"); Log.Info(key); processStats[key] = new ulong[] { (ulong)obj.GetPropertyValue("PercentProcessorTime"), (ulong)obj.GetPropertyValue("WorkingSet") }; } } } }
In my log, I see "Query built", and then nothing, and the program stops responding.
I tried with manual timeout settings and without it.
tomwardill
source share