private void Monitor(Action executeAction, string memberName = null)
        {
            TimeElapsedInfo timeElapsedInfo = new TimeElapsedInfo();
            DateTime        startTime       = DateTime.Now;

            timeElapsedInfo.ExecuteTime = startTime;
            try
            {
                executeAction();
                timeElapsedInfo.IsSuccess = true;
            }
            catch (Exception ex)
            {
                timeElapsedInfo.IsSuccess = false;
                timeElapsedInfo.Remark    = ex.Message;
                throw;
            }
            finally
            {
                timeElapsedInfo.TimeElapsed     = (DateTime.Now - startTime).TotalMilliseconds;
                timeElapsedInfo.CallMemberName  = memberName;
                timeElapsedInfo.TimeElapsedType = TimeElapsedType;
                _timeElapsedStatistic.AddTimeElapsedInfo(timeElapsedInfo);
            }
        }
        private async Task <T> MonitorAsyncFunction <T>(Task <T> task, TimeElapsedType elapsedType, string memberName = null)
        {
            TimeElapsedInfo timeElapsedInfo = new TimeElapsedInfo();
            DateTime        startTime       = DateTime.Now;

            timeElapsedInfo.ExecuteTime = startTime;
            try
            {
                timeElapsedInfo.IsSuccess = true;
                return(await task);
            }
            catch (Exception ex)
            {
                timeElapsedInfo.IsSuccess = false;
                timeElapsedInfo.Remark    = ex.Message;
                throw;
            }
            finally
            {
                timeElapsedInfo.TimeElapsed     = (DateTime.Now - startTime).TotalMilliseconds;
                timeElapsedInfo.CallMemberName  = memberName;
                timeElapsedInfo.TimeElapsedType = elapsedType;
                _timeElapsedStatistic.AddTimeElapsedInfo(timeElapsedInfo);
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// 添加消耗时间信息
 /// </summary>
 /// <param name="timeElapsedInfo">消耗时间信息</param>
 public void AddTimeElapsedInfo(TimeElapsedInfo timeElapsedInfo)
 {
     if (timeElapsedInfo != null)
     {
         _timeConsumerQueue.Enqueue(timeElapsedInfo);
     }
 }