コード例 #1
0
        /// <summary>
        /// Runs the given task on the world thread.
        /// </summary>
        /// <param name="task">The task to run.</param>
        /// <exception cref="ObjectDisposedException">
        /// If the server thread has already been stopped.
        /// </exception>
        internal void RunTask(IWorldTask task)
        {
            if (!m_Running)
            {
                throw new ObjectDisposedException("World thread already disposed!");
            }

            Interlocked.Increment(ref m_ActiveTasks);
            m_TaskList.Add(task);
        }
コード例 #2
0
        /// <summary>
        /// Runs a task on the world thread, but blocks the main thread until this
        /// task has finished executing. Any tasks which were scheduled before this
        /// task are completed first.
        /// </summary>
        internal void RunTaskSync(IWorldTask task)
        {
            RunTask(task);

            while (true)
            {
                if (!m_FinishedTasks.TryTake(out IWorldTask t, -1))
                {
                    throw new ApplicationException("Failed to retreive task!");
                }

                m_WorldContainer.EventQueue.RunEvents();
                Interlocked.Decrement(ref m_ActiveTasks);

                if (task == t)
                {
                    break;
                }
            }
        }