开发者

How can I use a perfomance counter for my process? C#

开发者 https://www.devze.com 2023-02-27 07:57 出处:网络
I have an application , and I need to show the total time of the process when this ends. I am using the Swith case,

I have an application , and I need to show the total time of the process when this ends.

I am using the Swith case,

case "4":
  Console.WriteLine("Generating file..." + "\n");
 _loader.GenerateBinaryLog(filePath, logSelected);
 Console.WriteLine("File Generated: " + 开发者_JAVA百科_writer.getBinaryFileName(filePath, Convert.ToInt32(logSelected)) + "\n");
 logSelected = "-1";
 Console.ReadKey();
 break; 

So, when the process ends I need to show the message and something like this: "process finished in 30 seconds"...


You should use the Stopwatch class:

var sw = new Stopwatch();
sw.Start();
//Do things...
sw.Stop();
Console.WriteLine("Operation took {0:#,0.0} seconds", sw.Elapsed.TotalSeconds);


You don't need a performance counter.

You can use a Stopwatch,

      var stopwatch = new System.Diagnostics.Stopwatch();
      stopwatch.Start();
      ... do work here
      stopwatch.Stop();
      TimeSpan ts = stopwatch.Elapsed;
      Console.WriteLine("  Elapsed {0:N2}", ts.TotalSeconds);


You don't need a performance counter to just put this info on the console: use a Stopwatch.

0

精彩评论

暂无评论...
验证码 换一张
取 消