in src/WebJobs.Extensions/Extensions/Files/Listener/FileListener.cs [65:103]
public async Task StartAsync(CancellationToken cancellationToken)
{
ThrowIfDisposed();
if (_watcher != null && _watcher.EnableRaisingEvents)
{
throw new InvalidOperationException("The listener has already been started.");
}
CreateFileWatcher();
FileProcessorFactoryContext context = new FileProcessorFactoryContext(_options.Value, _attribute, _triggerExecutor, _logger);
_processor = _fileProcessorFactory.CreateFileProcessor(context);
ExecutionDataflowBlockOptions options = new ExecutionDataflowBlockOptions
{
BoundedCapacity = _processor.MaxQueueSize,
MaxDegreeOfParallelism = _processor.MaxDegreeOfParallelism,
};
_workQueue = new ActionBlock<FileSystemEventArgs>(async (e) => await ProcessWorkItem(e), options);
// on startup, process any preexisting files that haven't been processed yet
ProcessFiles();
// Create a timer to cleanup processed files.
// The timer doesn't auto-reset. It resets itself as files
// are completed.
// We start the timer on startup so we have at least one
// cleanup pass
_cleanupTimer = new System.Timers.Timer()
{
AutoReset = false,
Interval = _rand.Next(5 * 1000, 8 * 1000)
};
_cleanupTimer.Elapsed += OnCleanupTimer;
_cleanupTimer.Start();
await Task.FromResult<bool>(true);
}