/// <summary> /// Start the event with a timer attached /// </summary> /// <param name="name">The name of the performance event.</param> /// <param name="duration">The time to monitor the hit count.</param> /// <param name="onTimeEllapsed">The Method to call when the specified time elapses.</param> public void StartTimedEvent(string name, TimeSpan duration, TimeEllapsedDelegate onTimeEllapsed) { if(!IsValidKey(name)) { return; } _events[name].StartTimed(duration, onTimeEllapsed); }
/// <summary> /// Start an iteration with an exact duration. /// </summary> /// <param name="duration">The duration to monitor the hit count.</param> /// <param name="onTimeEllapsed">The method to call when the specified time elapses.</param> public void StartTimed(TimeSpan duration, TimeEllapsedDelegate onTimeEllapsed) { lock(lockObject) { try { timerCompletedEvent = onTimeEllapsed; timing = true; Start(); timer = new Timer(TimerCallback, null, duration, TimeSpan.FromSeconds(0)); } catch(Exception e) { Console.WriteLine(e.Message); } } }