public bool HandleCommand(string command, ref Exception error)
 {
     try
     {
         ScriptingValue value = scriptingEnvironment.ParseValue(command);
         callback.ShowMessage(value.ToString());
         return(true);
     }
     catch (Exception ex)
     {
         error = ex;
         return(false);
     }
 }
Exemplo n.º 2
0
        private void buttonRun_Click(object sender, EventArgs e)
        {
            string text = textLaunch.Text;

            try
            {
                ScriptingValue value = env.ParseValue(text);
                textLaunch.Text = "";
                textLaunch.Select();
                textCode.Enabled    = false;
                textLaunch.Enabled  = false;
                buttonRun.Enabled   = false;
                buttonClear.Enabled = false;

                Thread interpretorThread = new Thread(new ParameterizedThreadStart(o => Run((ScriptingValue)o)));
                interpretorThread.Start(value);

                Thread waitingThread = new Thread(() =>
                {
                    bool terminated = false;
                    terminated      = interpretorThread.Join(10000);
                    if (!terminated)
                    {
                        interpretorThread.Abort();
                    }
                    this.Invoke(new MethodInvoker(() =>
                    {
                        if (!terminated)
                        {
                            callback.ShowError("10秒超时,停止脚本执行。");
                        }
                        textCode.Enabled    = true;
                        textLaunch.Enabled  = true;
                        buttonRun.Enabled   = true;
                        buttonClear.Enabled = true;
                    }));
                });
                waitingThread.Start();
            }
            catch (Exception ex)
            {
                callback.ShowError(ex.Message);
                textLaunch.SelectAll();
                textLaunch.Select();
            }
        }