Example #1
0
        public void Execute(TParameter param, CancellationToken token, Action callback = null)
        {
            _backgroundTask = _taskFactory.GetInstance(() =>
            {
                ExecuteInternal(param, token);
                callback?.Invoke();
            }, token);

            using var _ = LogContext.PushProperty("CorrelationID", new Guid());

            Logger.Information("Attempting to start a background task");
            try
            {
                _backgroundTask?.Start();
            }
            catch (OperationCanceledException e)
            {
                Logger.Information(e, "Background task was cancelled");
            }
            catch (Exception e)
            {
                Logger.Error(e, "Exception occured while executing a job");
                throw;
            }
        }