I've been told by a coworker that if my WMI system information gathering queries are forward-only and/or read-only, they'll be quite faster. That makes sense. But how do I do it?
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Generic Generics in Managed C++
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
You need to use EnumerationOptions class and set its Rewindable property to false. Here is an example:
You won't see any performance improvement unless you use it to enumerate a class with a large number of instances (like Cim_DataFile) and you will get to enumerate the returned ManagementObjectCollection only once. You also won't be able to use ManagementObjectCollection.Count, etc. As for read-only queries, I'm not sure how to make those.
Your co-worker must have meant using the semisynchronous method calls together with forward-only enumerators. In the semisynchronous mode, WMI method calls return immediately and objects are retrieved in the background and returned on demand once they are created. Also, when using semisynchronous mode to retrieve a large number of instances, it is recommended to obtain forward-only enumerators to improve the performance. These peculiarities are explained in this MSDN article.
As Uros has pointed out, to get a forward-only enumerator in semisynchronous mode, you need to use the
EnumerationOptions
class instance with theReturnImmediately
property set totrue
and theRewindable
property set tofalse
, e.g.: