public IBatchToken Start() { var sender = _plugin.Sender; var methodPost = sender.GetType() .GetMethods() .Where(p => p.IsGenericMethod && p.Name == nameof(sender.Post)) .Single(p => p.GetParameters().Length == 3); var batchToken = new BatchToken(_localQueue, _batchQueueProvider, _queueEvent, _triggerAllCompleted, _config); var cancellationToken = batchToken.CancellationToken; Task.Factory.StartNew(() => { while (!cancellationToken.IsCancellationRequested) { try { var type = _queueEvent.WaitEvent(cancellationToken); if (type == null) { continue; } PostWorker(type, methodPost); } catch (Exception ex) { _plugin.LogFault(ex); } } Flushing(methodPost); }); _batchQueueProvider.StartTimers(); return(batchToken); }
public object WaitEvent(CancellationToken cancellationToken) { return(_queueEvent.WaitEvent(cancellationToken)); }