Unfortunately, WMI is neither efficient nor reliable when it comes to handling its events. As I figured out a while ago, such handling is based simply on regular polling, which is always bad. Please see:
http://en.wikipedia.org/wiki/Pull_technology[
^],
http://en.wikipedia.org/wiki/Push_technology[
^],
http://en.wikipedia.org/wiki/Polling_%28computer_science%29[
^].
I mean, pull technology is always bad (when it comes to regular polling), push is good. In your case, at the moment when you query for files, they might not be currently polled, you have to wait for some indefinite time, when all files are finalized, closed, and then polled.
Alternatives? You could use
System.IO.FileSystemWatcher
:
http://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher%28v=vs.110%29.aspx[
^].
There is something you should be aware of though: the CodeProject member
John Simmons / outlaw programmer reported these problems:
FileSystemWatcher - Pure Chaos (Part 1 of 2)[
^],
FileSystemWatcher - Pure Chaos (Part 2 of 2)[
^].
—SA