/// <summary>
        /// Creates a new worker.
        /// </summary>
        /// <param name="context">The contextual information about what was produced.</param>
        /// <returns>The worker used to work the produced item.</returns>
        protected virtual IWorker CreateWorker(IProducerConsumerContext <TItem> context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            lock (syncRoot)
            {
                IWorker worker = null;

                try
                {
                    worker = pool.Get(() => OnConsume(context), null);
                    workers.Add(worker);

                    return(worker);
                }
                catch (Exception)
                {
                    worker?.Dispose();
                    throw;
                }
            }
        }
示例#2
0
 /// <summary>
 /// Creates a new worker.
 /// </summary>
 /// <param name="context">The contextual information about what was produced.</param>
 /// <returns>The worker used to work the produced item.</returns>
 protected virtual IWorker CreateWorker(IProducerConsumerContext <TItem> context)
 {
     return(pool.Get(() => OnConsume(context), null));
 }