コード例 #1
0
        public void PostScript(ScriptInstance i)
        {
            /* Do not enqueue the already queued script */
            bool enqueued = false;

            if (i.ThreadPool == null)
            {
                enqueued = m_ScriptTriggerQueue.EnqueueNewOnly(i);
            }

            if (enqueued)
            {
                int threadsCount = m_Threads.Count;
                if (m_ScriptTriggerQueue.Count > threadsCount && threadsCount < m_MaximumThreads)
                {
                    lock (m_Threads)
                    {
                        try
                        {
                            var tc = new ScriptThreadContext
                            {
                                ScriptThread = ThreadManager.CreateThread(ThreadMain),
                                ThreadPool   = this
                            };
                            tc.ScriptThread.Name         = "Script Worker: " + m_SceneID.ToString();
                            tc.ScriptThread.IsBackground = true;
                            tc.ScriptThread.Start(tc);
                            m_Threads.Add(tc);
                        }
                        catch
                        {
                            /* do not fail when we could not add a thread */
                        }
                    }
                }
            }
        }