예제 #1
0
        /// <summary>
        /// Increase or decrease the number of workers to process queued messages.
        /// </summary>
        /// <param name="value">New Value for the number of workers to use</param>
        public void SetNumberOfWorkers(int value)
        {
            lock (workers)
            {
                //Remove some if we need to
                while (workers.Count > value)
                {
                    workers[0].Stop();
                    workers.RemoveAt(0);
                }

                //Add workers if we need to
                while (workers.Count < value)
                {
                    var worker = new C2dmMessageTransportWorker();

                    worker.Task = Task.Factory.StartNew(messageTransportWork,
                                                        worker.CancelToken,
                                                        TaskCreationOptions.LongRunning).ContinueWith((Task t) =>
                    {
                        //TODO: Log error
                    }, TaskContinuationOptions.OnlyOnFaulted);

                    workers.Add(worker);
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Increase or decrease the number of workers to process queued messages.
        /// </summary>
        /// <param name="value">New Value for the number of workers to use</param>
        public void SetNumberOfWorkers(int value)
        {
            lock (workers)
            {
                //Remove some if we need to
                while (workers.Count > value)
                {
                    workers[0].Stop();
                    workers.RemoveAt(0);
                }

                //Add workers if we need to
                while (workers.Count < value)
                {
                    var worker = new C2dmMessageTransportWorker();

                    worker.Task = Task.Factory.StartNew(messageTransportWork,
                    worker.CancelToken,
                    TaskCreationOptions.LongRunning).ContinueWith((Task t) =>
                    {
                        //TODO: Log error

                    }, TaskContinuationOptions.OnlyOnFaulted);

                    workers.Add(worker);
                }
            }
        }