From the MSDN documentation for the FileInfo.Name property, I see that the data for the property is cached the first time it is called and will only be updated subsequently by using the Refresh method.
I’ve the following questions which I can’t find or aren’t too clear in the documentation:
-
Is the data for all properties cached at the same time?
-
Is the
Refreshmethod called on creation of theFileInfo, or only when a property is called for the first time? -
If I’ve called one property, e.g. the
Nameproperty, and it’s calledRefresh, will calling a different property, e.g. theDirectoryNameproperty, for the first time cause it to callRefreshagain, or is it only called by the first property accessed in the entire class (see question #1)? -
Can I pre-cache all the properties by calling
Refreshmanually? (Assuming it’s not pre-cached on construction of the object) -
Does calling
Refreshmanually cause properties which are pre-cached, e.g.CreationTime, to be refreshed as well?
At a guess, yes. It seems like a bit of a self-defeating “optimisation” for
FileInfoto fetch only the properties you’ve fetched before, especially when they can be (and probably are) all fetched in one API call.The fact that the documentation calls out
DirectoryInfomethods which serve up already-cachedFileInfos suggests quite strongly (to me, anyway) that simply constructing aFileInfodoesn’t cache anything. It makes sense – if you construct aFileInfodirectly, it might refer to a file that doesn’t exist yet (you plan to create it, for instance), whereas all the methods which return cachedFileInfos refer to files that exist at the time of the snapshot, under the assumption you’re going to use at least some of them.No, by my answer to question 1. That’s why the Refresh method is there.
I would imagine so (see answer 1).
Yes. See answer 3.