public void Start(Component.SLComponent root, params Type[] templates) { if (!_state.Is(EState.Closed)) { throw new InvalidOperationException($"wrong state: {_state.ToString()}"); } Task.Factory.StartNew(() => { var fq = _state.Frequency; var dispatcher = new Execution.Terminal.RawDispatcher(_state.EndPoint); var executorList = new List <Execution.ISLExecutor>(templates.Length); for (int i = 0; i != templates.Length; i++) { var exe = (Execution.ISLExecutor)Activator.CreateInstance(templates[i]); executorList.Add(exe); } _state.Set(EState.Running); while (_state.Is(EState.Running)) { var begin = Library.Ticker.MS; try { for (int i = 0; i != executorList.Count; i++) { try { executorList[i].ExecuteFrame(ref dispatcher, root); } catch (ArgumentException e) { Library.Logger.Error($"{_state.ToString()}\n[Engine::{executorList[i].GetType().Name}]\n{e.Message}\n{e.StackTrace}"); } catch (KeyNotFoundException e) { Library.Logger.Error($"{_state.ToString()}\n[Engine::{executorList[i].GetType().Name}]\n{e.Message}\n{e.StackTrace}"); } catch (Exception) { Library.Logger.Error($"{_state.ToString()}\n[Engine::{executorList[i].GetType().Name}]\n"); throw; } } } catch (Exception e) { Library.Logger.Exception(typeof(Engine), e); } finally { var end = Library.Ticker.MS; int leg = (int)(end - begin) - fq; if (leg < 0) { Thread.Sleep(-leg); } } } _state.Set(EState.Closed); }); }