private void TimerTick(object sender, ElapsedEventArgs e) { Logger.Log(nameof(TimerControlledScriptStarter), nameof(TimerTick), "0"); if (!ScriptStarted || Script.HasFinishedUnsuccessfully) { if (ScriptStarted && Script.HasFinishedUnsuccessfully && !AutoRestart) { timer.Stop(); HasFinishedUnsuccessfully = true; return; } StartScriptInThisTick = true; Logger.Log(nameof(TimerControlledScriptStarter), nameof(TimerTick), ScriptStarted.ToString()); } else if (Script.HasFinishedSuccessfully) { timer.Stop(); } timer.Interval = GetRandomInterval(); }
public static async Task <Exception> StartScriptAsync() { if (ScriptRunning) { ScriptInterface.Instance.Log("Script already running."); return(new Exception("Script already running.")); } else { try { ScriptInterface.exit = false; object script = await Task.Run(() => Compile(File.ReadAllText(LoadedScript))); LoadScriptConfig(script); if (_configured.TryGetValue(ScriptInterface.Instance.Config.Storage, out bool b) && !b) { ScriptInterface.Instance.Config.Configure(); } ScriptInterface.Instance.Handlers.Clear(); ScriptInterface.Instance.Runtime = new ScriptRuntimeVars(); CurrentScriptThread = new Thread(() => { ScriptStarted?.Invoke(); try { script.GetType().GetMethod("ScriptMain").Invoke(script, new object[] { ScriptInterface.Instance }); } catch (Exception e) { if (!(e is ThreadAbortException)) { Debug.WriteLine($"Error while running script: {e.Message}"); ScriptError?.Invoke(e); } } ScriptStopped?.Invoke(true); }); CurrentScriptThread.Name = "Script Thread"; CurrentScriptThread.Start(); return(null); } catch (Exception e) { return(e); } } }
private void TimerTick(object sender, ElapsedEventArgs e) { if (!ScriptStarted || Script.HasFinishedUnsuccessfully) { if (ScriptStarted && Script.HasFinishedUnsuccessfully && !AutoRestart) { timer.Stop(); HasFinishedUnsuccessfully = true; return; } StartScriptInThisTick = true; Logger.Log(nameof(SequentialScriptStarter), nameof(TimerTick), ScriptStarted.ToString()); } else if (Script.HasFinishedSuccessfully) { timer.Stop(); } }