public async Task <TResult> RunAsync([CallerMemberName] string?caller = null)
        {
            using (_counter?.Start())
            {
                TraceOperationStarted(caller !);
                var stopwatch = StopwatchSlim.Start();

                try
                {
                    var result = await AsyncOperation();

                    TraceOperationFinished(result, stopwatch.Elapsed, caller !);

                    return(result);
                }
                catch (Exception e)
                {
                    var resultBase = new BoolResult(e);

                    if (_isCritical)
                    {
                        resultBase.MakeCritical();
                    }

                    TraceResultOperationFinished(resultBase, stopwatch.Elapsed, caller !);

                    throw;
                }
            }
        }
Пример #2
0
        public async Task <TResult> RunAsync([CallerMemberName] string?caller = null)
        {
            using (_counter?.Start())
            {
                TraceOperationStarted(caller !);
                var stopwatch = StopwatchSlim.Start();

                try
                {
                    // No need to run anything if the cancellation is requested already.
                    _context.Token.ThrowIfCancellationRequested();

                    var result = await AsyncOperation();

                    TraceOperationFinished(result, stopwatch.Elapsed, caller !);

                    return(result);
                }
                catch (Exception e)
                {
                    var resultBase = new BoolResult(e);

                    if (_isCritical)
                    {
                        resultBase.MakeCritical();
                    }

                    MarkResultIsCancelledIfNeeded(resultBase, e);

                    TraceResultOperationFinished(resultBase, stopwatch.Elapsed, caller !);

                    throw;
                }
            }
        }