Why are WMI Queries so slow sometimes?

Josh Clark picture Josh Clark · Sep 14, 2009 · Viewed 11.5k times · Source

I am using System.Management namespace in a .Net to execute various WMI queries against a remote server. In my logs I can see that sometimes the queries take 30 or 40 seconds to complete while other times the queries complete in less than a second.

When I see these slow queries, I try to connect to the box using wbemtest, but it always connects and executes the query quickly.

Any ideas, pointers, suggestions?

I did notice when looking at System.Management.ManagementScope in reflector that it seems to leak a IWbemServices pointer. It looks like this is a COM Interface that needs to have Release called on it (Marshal.ReleaseComObject()). I'm not sure if that is related or not. I do connect to lots of different servers during the life of the process.

Answer

SwDevMan81 picture SwDevMan81 · Sep 15, 2009

You could try and set the WITHIN field to see if it forces the query to happen sooner. Could you post the query you are using? That might help debug any further issues