.Net File.GetLastAccessTime updates Last Access Time of file

别等时光非礼了梦想. 提交于 2019-12-10 14:58:41

问题


We are using below line to get Last access date and time of the file.

DateTime dtLastAccesstime = File.GetLastAccessTime(sFilePath);

But we are facing strange problem, the above call itself modifies the Last access time. So effectively we are getting current time as last access time.


回答1:


You may find this post useful, in particular:

Starting in Windows Vista, maintaining the last-access time is disabled by default.

Which means that nowadays most operating systems won't maintain the last access time (which I suppose could account for the odd behaviour you are seeing).

Even if this is not the case this post highlights some of the many scenarios whereby the last access time could have been updated when you didn't mean to - can you be sure that your application doesn't perform any other file access?



来源:https://stackoverflow.com/questions/8312376/net-file-getlastaccesstime-updates-last-access-time-of-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!