Exemplo n.º 1
0
        public static void QueueAction(Action queueableAction)
        {
            lock (locker) {
                PendingActions.Enqueue(queueableAction);
            }

            //if we don't have all our threads, spin one up with this task.
            if (AvailableThreads.Count < MAX_THREADS)
            {
                var thread = new Thread(ExecuteAction);
                AvailableThreads.Add(thread);
                thread.Start();
            }
            //sets the threadsync, causing the actionExecute to stop waiting
            lock (locker) {
                ThreadSync.Set();
            }
        }
Exemplo n.º 2
0
        // This is the method the flight computer calls when you, the programmer, execute a work item.
        public static void QueueWorkItem(WorkItem thingToQueue)
        {
            //first, add the work item to the queue of work items (if something came before, it comes first)
            lock (locker) {
                PendingWorkItems.Enqueue(thingToQueue);
            }

            //If we haven't reached our MAX_THREADS yet, go ahead and create one...
            //    Note" this will only run the first MAX_THREADS (3) times we execute
            //    a work item in the flight computer - then, we'll have our 3 threads,
            //    and this if block will be skipped.
            if (AvailableThreads.Count < MAX_THREADS)
            {
                var thread = new Thread(ThreadWorker);
                AvailableThreads.Add(thread);
                thread.Start();
            }

            //Let our threadworkers know that there's something in the queue they should grab.
            lock (locker) {
                ThreadSync.Set();
            }
        }