private void ScriptProcessor() { ThreadScriptEngine = this; object v; string s, r; while (!IsClosing) { try { if (IsPaused) { Thread.Sleep(200); } else { s = ScriptQueue.Take();//ParentShell.Interrupter.GetToken); // Ignore interrupt here, Close will stop Q. if ((s != null) && (s.Length > 0)) { r = null; IsRunning = true; try { this.Global.ErrorStack.Clear(); //this.SetDebugMode(true); v = this.Run(s); if (v != null) { r = v.ToString(); } } catch (Exception e) { r = "Error in script:\n" + GetLine(s) + "\n"; s = e.Message; r += s + "\n"; foreach (string m in this.Global.ErrorStack) { if (!s.StartsWith(m)) { r += m + "\n"; } } } IsRunning = false; if ((r != null) && (r.Length > 0)) { Shell.Write(ParentShell.ShellId, r, false, true); // TODO: set params properly. } } } // } catch(OperationCanceledException) { // This is generated when Take is interrupted prior to closing. // //IsClosing = true; // break; } catch (Exception e) { Shell.WriteLine(e.Message); // TODO: writes to console. } } }
private void ScheduleProcessor() { while (!IsClosing) { try { if (!IsPaused && SchedulingEnabled) { lock (TaskQueue) { int n = TaskQueue.Count; while (n-- > 0) { Task t = TaskQueue[0]; if (--t.DelayDifference <= 0) { if (TaskQueue.Count > 1) { TaskQueue[1].DelayDifference += t.DelayDifference; } TaskQueue.RemoveAt(0); if (t.When == Task.TaskAction.Every) { AddTask(t); } if (t.IsEnabled) { ScriptQueue.Add(t.Command); } } else { break; } } } } Thread.Sleep(1000); } catch (Exception e) { Shell.WriteLine(e.Message); // TODO: writes to console. } } }