gpt4 book ai didi

C#:GetCreationTime 和 GetLastWriteTime 给出了相同的时间,但我的文件大小随着时间的推移而增加

转载 作者:太空宇宙 更新时间:2023-11-03 14:58:44 26 4
gpt4 key购买 nike

我创建了一个性能文件 (.blg) 并开始收集性能参数。

文件修改日期从未在 Windows 资源管理器上更新,它始终显示创建日期,如下所示,但随着时间的推移文件大小在增加。

enter image description here

现在我想获取文件创建数据和上次写入日期,但下面的代码给了我相同的日期/时间(创建时间)。如何获取文件的最后写入时间?

Console.WriteLine(File.GetCreationTime(@"C:\Temp\BasicPerfCounters.blg"));

Console.WriteLine(File.GetLastWriteTime(@"C:\Temp\BasicPerfCounters.blg"));

最佳答案

来自MSDN的回答:

This method may return an inaccurate value, because it uses native functions whose values may not be continuously updated by the operating system. Each operating system manages the last write time according to its own rules. To improve performance, an operating system might not set the last write time value to the exact time of the last write operation, but might set it to a close approximation instead.

https://msdn.microsoft.com/en-us/library/system.io.file.getlastwritetime(v=vs.110).aspx

因此,出于性能考虑,操作系统似乎没有更改上次写入时间。这是特别有效的,因为该进程似乎非常频繁地更新文件并且操作系统不打算相应地更新文件上次写入时间。

因此,我建议将上次更新时间保存在内存变量中,甚至保存在数据库中。但是,我认为最好的方法是从您正在使用的性能文件 (.blg) 中获取上次写入时间。

注意:如果您需要从 .blg 中读取数据时出现问题(包括上次保存的操作的上次写入时间),您可以考虑将格式更改为逗号分隔值,例如使用工具:RELOG。 EXE文件。 And here is Two Minute Drill article: https://blogs.technet.microsoft.com/askperf/2008/05/20/two-minute-drill-relog-exe/ .

关于C#:GetCreationTime 和 GetLastWriteTime 给出了相同的时间,但我的文件大小随着时间的推移而增加,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47427922/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com