Example #1
0
        /// <summary>
        /// Procedure begins the TaskProxy wait operation.
        /// TaskProxy will send all queued tasks to the TaskPool for
        /// servicing and change its state to enuTaskProxyStatus.WaitingOnResults.
        /// Once the state change takes place the TaskProxy will no longer accept
        /// task requests hence calling AddTaskRequest after this state change will
        /// result in an InvalidOperationException being thrown.
        /// </summary>
        public void StartWait()
        {
            lock (m_requestQ.SyncRoot)
            {
                // If we are not about to transition from AcceptingRequests
                // then we have nothing to do here, so exit
                if (m_status != enuTaskProxyStatus.AcceptingRequests)
                {
                    return;
                }

                // Pass all the requests we have to the TaskPool
                // do not empty the requestQ, we need to preserve the ordering
                // just in case external clients don't
                IEnumerator it = m_requestQ.GetEnumerator();
                while (it.MoveNext())
                {
                    TaskPool.QueueTask((TaskRequest)it.Current);
                }

                // Once Wait is called, Proxy no longer accepts new requests
                // we indicate this by changing state
                m_status = enuTaskProxyStatus.WaitingOnResults;
            }
        }
Example #2
0
 /// <summary>
 /// Procedure resets the state of a TaskProxy.
 /// Clears: The request queue, the results table, and the TaskProxy
 /// state.
 /// </summary>
 public void Reset()
 {
     lock (this)
     {
         m_requestQ.Clear();
         m_results.Clear();
         m_status = enuTaskProxyStatus.AcceptingRequests;
         m_condition.Reset();
     }
 }
Example #3
0
        /// <summary>
        /// Procedure represents the notification callback provided by the
        /// TaskProxy. This callback is invoked whenever a task the TaskProxy
        /// is waiting on has been serviced by the TaskPool. When all the tasks the
        /// proxy is waiting on have been serviced it will signal external clients
        /// using the condition variable reference passed from the client at
        /// TaskProxy construction.
        /// </summary>
        /// <param name="tceArg"></param>
        private void OnTPTaskComplete(TPTaskCompleteEventArgs tceArg)
        {
            lock (m_results.SyncRoot)
            {
                // Index results by TaskID
                m_results.Add(tceArg.TaskID, tceArg);
                m_nTasksPending--;

                if (m_nTasksPending == 0)
                {
                    // Indicate results are ready by changing state
                    m_status = enuTaskProxyStatus.ResultsReady;
                    // Signal to any waiting client
                    m_condition.Set();
                }
            }
        }