【发布时间】:2019-07-28 12:04:55
【问题描述】:
我正在使用秒表,我想估计从开始到结束需要多长时间。
它看起来像一个非常简单的复合体。我实例化了秒表,启动它,然后停止它,然后通过编写一个方法 .elapsed 它应该为我提供从启动到停止所需的时间。
不幸的是,它总是为我提供 00:00:00。
我必须在我的电脑上设置一些特定于我的文化的东西吗?
我也尝试过 .StartNew() 但无济于事。
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
string juniorDevOpsFolder = "JuniorDevOps";
string targetPath = Directory.GetCurrentDirectory();
int endIndex = targetPath.IndexOf(juniorDevOpsFolder);
var juniorDevOpsPath = targetPath.Substring(0, endIndex + juniorDevOpsFolder.Length);
string directory = "Files";
string targetDirectory = Path.Combine(juniorDevOpsPath, directory);
ProcessDirectory(targetDirectory);
stopwatch.Stop();
// Write hours, minutes and seconds.
Console.WriteLine("Time elapsed: {0:hh\\:mm\\:ss}", stopwatch.Elapsed);
同样,输出是 00:00:00
【问题讨论】:
-
什么是
ProcessDirectory?? -
这看起来不像minimal reproducible example。
-
我调用了方法,但是这里不相关,重点关注秒表部分。
-
您调用的方法非常相关,因为它似乎比1s快。你应该注意到的..!