我目前在C#中使用循环来生成文件,但程序需要几秒钟才能真正做到这一点,我觉得程序用户会从更新的进度条中受益,以告诉他们循环到底有多远,以便他们可以估计循环何时结束并生成所有文件。估计进度条的循环时间
我想知道是否有计算时间的方法,它会花费一个循环来完成或更新循环的进度条,以显示循环剩余的进度。
这是我的循环。
String GeneratedLevelName;
int levelx = 0;
int levely = 0;
for (int i = 0; i < GmapLevelArea; i ++) {
if (levelx >= (GmapWidth - 1)) {
levelx = 0;
levely ++;
GeneratedLevelName = (GmapPrefix + "_" + levelx + "_" + levely + ".nw");
File.Copy(ApplicationDirectory + TemplateFileName, GmapDirectory + GeneratedLevelName);
GmapFile.AppendLine('"' + GeneratedLevelName + '"' + ",");
} else {
levelx ++;
GeneratedLevelName = (GmapPrefix + "_" + levelx + "_" + levely + ".nw");
File.Copy(ApplicationDirectory + TemplateFileName, GmapDirectory + GeneratedLevelName);
GmapFile.Append('"' + GeneratedLevelName + '"' + ",");
}
}
任何帮助,非常感谢。
您必须手动计算的时间。这当然是可能的。你也可以显示所取得的进展(就像每次迭代所做的火灾事件)。如果每次迭代的时间大致相等,后者可能就足够了。 – bas 2013-03-16 13:07:05
这是一个很好的替代建议。我会考虑手动计算时间。谢谢你的帮助。 – 2013-03-16 13:10:11
如果你的文件足够大,你想获得一个真正的进度条来复制字节,请看下面这些问题:[我可以在.NET中使用FileInfo.CopyTo()显示文件复制进度吗?](http:// stackoverflow.com/questions/187768/can-i-show-file-copy-progress-using-fileinfo-copyto-in-net)和[带进度条的文件复制](http://stackoverflow.com/questions/6044629/file-copy-with-progress-bar) – psubsee2003 2013-03-16 13:22:32