コード例 #1
0
        /// <summary>
        ///   Stopping the calculation if still in progress
        /// </summary>
        /// <remarks>
        ///   This is typically to be called when there have been changes
        ///   made in the model resulting in changes to the element being analyzed.
        /// </remarks>
        ///
        public void StopCalculation()
        {
            // We first signal we do not want more results,
            // so the work-thread knows to stop if it is still around.

            m_results.SetCompleted();

            // If the thread is alive, we'll wait for it to finish
            // It will not take longer than one calculation cycle.

            if (m_threadAgent != null)
            {
                if (m_threadAgent.IsThreadAlive)
                {
                    m_threadAgent.WaitToFinish();
                }
                m_threadAgent = null;
            }
        }
コード例 #2
0
        /// <summary>
        ///   Starting a work-thread to perform the calculation
        /// </summary>
        /// <returns>
        ///   True if the thread started off successfully.
        /// </returns>
        public bool StartCalculation()
        {
            // we need to get the face from the reference we track
            Face theface = GetReferencedFace();

            if (theface == null)
            {
                return(false);
            }

            // An instance for the result exchange
            m_results = new SharedResults();

            // The agent does not need the face nor the reference.
            // It can work with just the bounding box and a density of the grid.
            // We also pass the Results as an argument. The thread will be adding calculated results
            // to that object, while here in the analyzer we will read from it. Both operations are thread-safe;

            m_threadAgent = new ThreadAgent(theface.GetBoundingBox(), 10, m_results);

            // now we can ask the agent to start the work thread
            return(m_threadAgent.Start());
        }