我目前在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