プロセス中に経過した時間を与える方法が必要です。プロセスの開始時に呼び出し、プロセスの終了時に再度呼び出すと、メソッドは経過した合計時間を出力します。
これは私の方法ですが、常に00:00に時刻を出力します。なぜこれが起こっているのですか?
public void GetTimeElapsed(string filePath, int logSelected, bool time, IUserOptions userOptions)
{
var stopwatch = new System.Diagnostics.Stopwatch();
LogBinaryWriter BinaryWriter = new LogBinaryWriter();
string timeElapsed = "";
if(time == true)
{
stopwatch.Start();
}
if (time == false)
{
stopwatch.Stop();
TimeSpan timeSpan = stopwatch.Elapsed;
timeElapsed = (string.Format("\nFile Generated: {0}\nTime Elapsed: {1} minute(s) {2} second(s)",
BinaryWriter.CreateLogFileName(filePath, Convert.ToInt32(logSelected)),
timeSpan.Minutes, timeSpan.Seconds, timeSpan.Milliseconds / 10 + "\n"));
userOptions.DisplayUserMessage(timeElapsed);
}
}