Example #1
0
        public bool Start()
        {
            lock (this)
            {
                if (Started == false)
                {
                    clearExisting();
                    UnitAdded += new EventHandler <ThreadPoolItemEventArg>(threadPoolManager_UnitAdded);
                    for (int i = 0; i < MaxThreadCount; i++)
                    {
                        ThreadPoolItem item = new ThreadPoolItem(this, i);
                        item.UnitStarted  += new EventHandler <ThreadPoolItemEventArg>(item_UnitStarted);
                        item.UnitFinished += new EventHandler <ThreadPoolItemEventArg>(item_UnitFinished);
                        PoolItemList.Add(item);
                        Thread newThread = new Thread(new ThreadStart(item.ExecThreadItem));
                        lstThread.Add(newThread);
                        newThread.Start();

                        item.Status = ThreadPoolItem.PoolItemStatus.Active;
                    }
                    TriggerThread         = new Thread(new ThreadStart(this.invokeThread));
                    isTriggerThreadFinish = false;
                    TriggerThread.Start();

                    Started = true;
                    return(true);
                }
            }

            return(false);
        }
Example #2
0
        //Should be Synchronized
        public StatusCode AddExecutionUnitIfAvailable(ExecutionUnit unit, bool ReturnIfErrorFound)
        {
            object[] args = new object[1];
            if (ReturnIfErrorFound && ErrorList.Count > 0)
            {
                args[0] = ErrorList.Count;
                return
                    (new CommonStatusCode(CommonStatusCode.QUEUE_ERROR_FOUND, args, Config, ApplicationId));
            }
            ThreadPoolItem nextItem = null;

            while ((nextItem = AvailablePoolItem) == null)
            {
                System.Threading.Thread.Sleep(0);
            }
            if (ReturnIfErrorFound && ErrorList.Count > 0)
            {
                args[0] = ErrorList.Count;
                return
                    (new CommonStatusCode(CommonStatusCode.QUEUE_ERROR_FOUND, args, Config, ApplicationId));
            }
            StatusCode retVal = AddExecutionUnit(unit);

            return(retVal);
        }
Example #3
0
 private void invokeThread()
 {
     while (isTriggerThreadFinish == false)
     {
         resetEvent.WaitOne();
         while (queueInvokeRequest.Count > 0)
         {
             ThreadPoolItem targetItem = null;
             lock (queueInvokeRequest)
             {
                 targetItem = queueInvokeRequest.Dequeue();
             }
             if (targetItem != null)
             {
                 targetItem.Trigger();
             }
         }
     }
 }
Example #4
0
        private void assignExecutionUnit()
        {
            ThreadPoolItem pool_item = null;

            lock (this)
            {
                if (ExecutionUnitQueue.Count > 0)
                {
                    pool_item = AvailablePoolItem;
                    if (pool_item != null)
                    {
                        lock (pool_item)
                        {
                            if (pool_item.ExecutionUnit == null && pool_item.IsAvailable)
                            {
                                lock (ExecutionUnitQueue)
                                {
                                    ExecutionUnit targetUnit = ExecutionUnitQueue.Dequeue();
                                    if (targetUnit != null)
                                    {
                                        pool_item.ExecutionUnit = targetUnit;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            if (pool_item != null && pool_item.Status == ThreadPoolItem.PoolItemStatus.UnitAttached)
            {
                lock (queueInvokeRequest)
                    queueInvokeRequest.Enqueue(pool_item);
                resetEvent.Set();
            }
            else
            {
                isTransitioning = false;
            }
        }