Example #1
0
    ////////////////////////////////////////////////////////////////////////////////

    public void Run(System.Action action)
    {
        //Run any threads that are waiting.
        for (int i = MaxThreads; i < _Threads.Count; ++i)
        {
            if (_Threads[i].State == ThreadState.RUNNING && _Threads[i].IsWaiting)
            {
                _Threads[i].Run(action);
                return;
            }
        }

        //Create new thread.
        if (_Threads.Count < MaxThreads)
        {
            FogThread newthread = new FogThread(this);
            _Threads.Add(newthread);
            newthread.Run(action);
            return;
        }

        //No available threads so lock queue and add the action.
        lock (_ActionQueue)
        {
            _ActionQueue.Add(action);
        }
    }
Example #2
0
    ////////////////////////////////////////////////////////////////////////////////

    /// <summary>
    /// Requests new action from the queue
    /// </summary>
    /// <returns></returns>
    internal System.Action RequestNewAction(FogThread thread)
    {
        lock (_ActionQueue)
        {
            if (_ActionQueue.Count > 0)
            {
                System.Action newaction = _ActionQueue[_ActionQueue.Count - 1];
                _ActionQueue.RemoveAt(_ActionQueue.Count - 1);
                return(newaction);
            }
        }
        return(null);
    }