using System; using System.Collections.Generic; using System.Text; namespace Volian.Base.Library { public class VlnTimer { private DateTime _LastTime = DateTime.Now; public DateTime LastTime { get { return _LastTime; } set { _LastTime = value; } } private string _LastProcess = "Initialize"; public string LastProcess { get { return _LastProcess; } set { _LastProcess = value; } } public string ActiveProcess { get { return _LastProcess; } set { DateTime tNow = DateTime.Now; TimeSpan ts = tNow - LastTime; LastTime = tNow; if (!ElapsedTimes.ContainsKey(LastProcess)) ElapsedTimes.Add(LastProcess, ts); else ElapsedTimes[LastProcess] += ts; LastProcess = value; } } Dictionary _ElapsedTimes = new Dictionary(); public Dictionary ElapsedTimes { get { return _ElapsedTimes; } set { _ElapsedTimes = value; } } public void ShowElapsedTimes() { ActiveProcess = "fini"; Console.WriteLine("'Process'\t'Elapsed'"); foreach (string proc in ElapsedTimes.Keys) Console.WriteLine("'{0}'\t{1}", proc, ElapsedTimes[proc].TotalSeconds); } public void ShowElapsedTimes(string title) { Console.WriteLine(title); ShowElapsedTimes(); } } }