Exemple #1
0
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            while (!stoppingToken.IsCancellationRequested)
            {
                var message = await _processor.ChannelReader.ReadAsync(stoppingToken);

                if (message == null)
                {
                    continue;
                }

                List <YadlMessage> messages;
                lock (_memberLock)
                {
                    _processor.Messages.Add(message);
                    if (_processor.Messages.Count != _options.BatchSize)
                    {
                        continue;
                    }

                    messages = _processor.Messages.ToList();
                    _processor.Messages.Clear();
                }

                if (messages.Count > 0)
                {
                    await _sqlServerBulk.ExecuteAsync(messages, stoppingToken);
                }
            }
        }
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            while (!stoppingToken.IsCancellationRequested)
            {
                await Task.Delay(_options.BatchPeriod, stoppingToken);

                List <YadlMessage> messages;
                lock (_memberLock)
                {
                    if (_processor.ChannelReader.TryRead(out var message))
                    {
                        _processor.Messages.Add(message);
                    }

                    messages = _processor.Messages.ToList();
                    _processor.Messages.Clear();
                }

                if (messages.Count > 0)
                {
                    await _sqlServerBulk.ExecuteAsync(messages, stoppingToken);
                }
            }
        }