Exemplo n.º 1
0
        /// <summary>
        /// Starts the queue
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="functionToRun">The function to run to handle messages.</param>
        public void Start <T>(Action <IReceivedMessage <T>, IWorkerNotification> functionToRun)
            where T : class
        {
            ThrowIfDisposed();
            Guard.NotNull(() => functionToRun, functionToRun);

            if (_taskFactory.Value.Scheduler == null)
            {
                throw new DotNetWorkQueueException("A scheduler must be created before starting the queue");
            }

            if (!_taskFactory.Value.Scheduler.Started)
            {
                throw new DotNetWorkQueueException("The scheduler must be started before starting the queue");
            }

            //let the scheduler know it has another client
            if (!_schedulerId.HasValue)
            {
                _schedulerId = _taskFactory.Value.Scheduler.Subscribe();
            }

            _queue.Start <T>(
                (message, notifications) =>
                _schedulerMessageHandler.HandleAsync(WorkGroup, message, notifications, functionToRun, _taskFactory.Value));
        }