public async Task TryExecuteAsync()

in src/Microsoft.Azure.WebJobs.Host/Executors/FunctionExecutor.cs [79:158]


        public async Task<IDelayedException> TryExecuteAsync(IFunctionInstance functionInstance, CancellationToken cancellationToken)
        {
            var functionInstanceEx = (IFunctionInstanceEx)functionInstance;
            var logger = _loggerFactory.CreateLogger(LogCategories.CreateFunctionCategory(functionInstanceEx.FunctionDescriptor.LogName));
            var functionStartedMessage = CreateStartedMessage(functionInstanceEx);
            var parameterHelper = new ParameterHelper(functionInstanceEx);
            ExceptionDispatchInfo exceptionInfo = null;
            string functionStartedMessageId = null;
            FunctionInstanceLogEntry instanceLogEntry = null;
            Stopwatch sw = Stopwatch.StartNew();
            string concurrencyFunctionId = functionInstanceEx.FunctionDescriptor.SharedListenerId ?? functionInstanceEx.FunctionDescriptor.Id;
            
            try
            {
                Interlocked.Increment(ref _outstandingInvocations);
                if (_concurrencyManager.Enabled)
                {
                    _concurrencyManager.FunctionStarted(concurrencyFunctionId);
                }

                using (_resultsLogger?.BeginFunctionScope(functionInstanceEx, HostOutputMessage.HostInstanceId))
                using (parameterHelper)
                {
                    try
                    {
                        parameterHelper.Initialize();
                        instanceLogEntry = CreateInstanceLogEntry(functionStartedMessage);
                        await _functionEventCollector.AddAsync(instanceLogEntry);

                        functionStartedMessageId = await ExecuteWithLoggingAsync(functionInstanceEx, functionStartedMessage, instanceLogEntry, parameterHelper, logger, cancellationToken);
                    }
                    catch (Exception exception)
                    {
                        functionStartedMessage.Failure = FunctionFailure.FromException(exception);
                        exceptionInfo = ExceptionDispatchInfo.Capture(exception);
                        exceptionInfo = await InvokeExceptionFiltersAsync(parameterHelper.JobInstance, exceptionInfo, functionInstanceEx, parameterHelper.FilterContextProperties, logger, cancellationToken);
                    }
                    finally
                    {
                        functionStartedMessage.ParameterLogs = parameterHelper.ParameterLogCollector;
                        functionStartedMessage.EndTime = DateTimeOffset.UtcNow;
                    }

                    // If function started was logged, don't cancel calls to log function completed.
                    bool loggedStartedEvent = functionStartedMessageId != null;
                    _functionInstanceLogger.LogFunctionCompleted(functionStartedMessage);

                    if (instanceLogEntry != null)
                    {
                        CompleteInstanceLogEntry(instanceLogEntry, functionStartedMessage.Arguments, exceptionInfo);
                        await _functionEventCollector.AddAsync(instanceLogEntry);
                        _resultsLogger?.LogFunctionResult(instanceLogEntry);
                    }

                    if (loggedStartedEvent)
                    {
                        _functionInstanceLogger.DeleteLogFunctionStarted(functionStartedMessageId);
                    }
                }

                if (exceptionInfo != null)
                {
                    await HandleExceptionAsync(functionInstanceEx.FunctionDescriptor.TimeoutAttribute, exceptionInfo, _exceptionHandler);
                }
            }
            finally
            {
                sw.Stop();
                if (_concurrencyManager.Enabled)
                {
                    _concurrencyManager.FunctionCompleted(concurrencyFunctionId, sw.Elapsed);
                }

                Interlocked.Decrement(ref _outstandingInvocations);

                ((IDisposable)functionInstanceEx)?.Dispose();
            }

            return exceptionInfo != null ? new ExceptionDispatchInfoDelayedException(exceptionInfo) : null;
        }