public async Task <IList <IDateRangeBlockContext> > GetDateRangeBlocksAsync(Func <IFluentDateRangeBlockDescriptor, object> fluentBlockRequest) { if (!IsExecutionContextActive) { throw new ExecutionException(NotActiveMessage); } var fluentDescriptor = fluentBlockRequest(new FluentRangeBlockDescriptor()); var settings = (IBlockSettings)fluentDescriptor; var request = ConvertToDateRangeBlockRequest(settings); if (ShouldProtect(request)) { var csContext = CreateClientCriticalSection(); try { var csStarted = await csContext.TryStartAsync(new TimeSpan(0, 0, 20), 3).ConfigureAwait(false); if (csStarted) { return(await _blockFactory.GenerateDateRangeBlocksAsync(request).ConfigureAwait(false)); } throw new CriticalSectionException("Could not start a critical section in the alloted time"); } finally { await csContext.CompleteAsync().ConfigureAwait(false); } } else { return(await _blockFactory.GenerateDateRangeBlocksAsync(request).ConfigureAwait(false)); } }