Beispiel #1
0
 /// <summary>
 /// Stop timer using timer name.
 /// </summary>
 /// <param name="timerName">Timer name.</param>
 /// <exception cref="IndexOutOfRangeException">There is no timer by name <paramref name="timerName"/>.</exception>
 public void StopTimer(string timerName)
 {
     lock (syncObject)
     {
         if (stopwatchDictionary.ContainsKey(timerName))
         {
             StopwatchInfo stopwatchInfo = stopwatchDictionary[timerName];
             stopwatchInfo.Stop();
         }
         else
         {
             string msg = string.Format("There is no timer by name {0}.", timerName);
             throw new IndexOutOfRangeException(msg);
         }
     }
 }
Beispiel #2
0
 /// <summary>
 /// Start timer using timer name.
 /// </summary>
 /// <param name="timerName">Timer name.</param>
 public void StartTimer(string timerName)
 {
     lock (syncObject)
     {
         StopwatchInfo stopwatchInfo;
         if (stopwatchDictionary.ContainsKey(timerName))
         {
             stopwatchInfo = stopwatchDictionary[timerName];
         }
         else
         {
             stopwatchInfo = new StopwatchInfo(timerName);
             stopwatchDictionary.Add(timerName, stopwatchInfo);
         }
         stopwatchInfo.Start();
     }
 }
Beispiel #3
0
        /// <summary>
        /// Display statistic that manager has for current timer.
        /// </summary>
        /// <param name="timerName">Timer name.</param>
        public void DisplayStatistic(string timerName)
        {
            StringBuilder stringBuilder = new StringBuilder();

            lock (syncObject)
            {
                if (stopwatchDictionary.ContainsKey(timerName))
                {
                    StopwatchInfo stopwatchInfo = stopwatchDictionary[timerName];

                    stringBuilder.AppendLine("-====== Statistic for " + timerName + " ======-");
                    stringBuilder.AppendLine(string.Format("Info: {0}", stopwatchInfo));
                    stringBuilder.AppendLine("-==== End statistic for " + timerName + " ====-");
                }
                else
                {
                    stringBuilder.AppendLine("There is no information about " + timerName);
                }
            }

            logger.WriteDebug(stringBuilder.ToString());
        }