Esempio n. 1
0
        public ThreadPoolWorker()
        {
            handleWorkItemCallBack = o =>
            {
                QueuedCallback queuedCallback = (QueuedCallback)o;
                try
                {
                    queuedCallback.Callback(queuedCallback.State);
                }
                finally
                {
                    lock (queuedCallbackPool)
                        queuedCallbackPool.ReleaseItem(queuedCallback);
                    DoneWorkItem();
                }
            };

            handleLoopCallBack = state =>
            {
                LoopState <T> loopS = (LoopState <T>)state;
                for (int i = loopS.StartIndex; i <= loopS.EndIndex; i++)
                {
                    loopS.Action(loopS.Items[i]);
                }
                lock (loopStatePool)
                    loopStatePool.ReleaseItem(loopS);
            };
        }
Esempio n. 2
0
        public void QueueWorkItem(Action act, object state)
        {
            ThrowIfDisposed();
            QueuedCallback qc = new QueuedCallback();

            qc.Callback = (x => act());
            qc.State    = state;
            lock (_done)
                _remainingWorkItems++;
            ThreadPool.QueueUserWorkItem(new WaitCallback(HandleWorkItem), qc);
        }
Esempio n. 3
0
        private void HandleWorkItem(object state)
        {
            QueuedCallback qc = (QueuedCallback)state;

            try
            {
                qc.Callback(qc.State);
            }
            finally
            {
                DoneWorkItem();
            }
        }