예제 #1
0
        void CompileScript()
        {
            // try start compiling current edited script
            if (m_CompileTask == null || m_CompileTask.IsCompleted)
            {
                string script = m_TextEditor.Text;
                m_CompileTask = Task.Factory.StartNew(() =>
                {
                    System.Threading.Thread.CurrentThread.Name = "ScriptEditor.Compile";
                    CompiledCode code = null;
                    try
                    {
                        code = ComponentManager.Compile(script);
                        Message("");
                    }
                    catch (SyntaxErrorException ex)
                    {
                        Message(string.Format("Line {0}/{1}: {2}", ex.Line, ex.Column, ex.Message));
                    }
                    catch (Exception ex)
                    {
                        Message(ex.Message);
                    }
                    finally
                    {
                        if (ScriptChangedHandler != null)
                        {
                            ScriptChangedHandler(new ScriptChangedEventArgs(m_Reference, script, code));
                        }
                    }

                    // if any last requested frame exist, start loading of this frame at least
                    if (m_PendingRequest)
                    {
                        m_PendingRequest = false;
                        CompileScript();
                    }
                });
            }
            // because compiling is in progress, save last request
            else
            {
                m_PendingRequest = true;
            }
        }