/// <summary> /// Ask the program to stop. /// </summary> /// <param name="callback">The cross-AppDomain task proxy.</param> internal void Stop(MarshaledResultSetter callback) { Requires.NotNull(_middleware, nameof(_middleware)); if (Verbose) { ChangeState(this, new BaZicInterpreterStateChangeEventArgs(L.BaZic.Runtime.BaZicInterpreter.StopRequested)); } Stop(true); callback.NotifyEndTask(); }
/// <summary> /// Initializes the start process for release and debug mode. /// </summary> /// <param name="callback">The cross-AppDomain task proxy.</param> /// <param name="action">The action to run in the flow.</param> /// <param name="verbose">Defines if the verbose mode must be enabled or not.</param> /// <param name="args">The arguments to pass to the entry point.</param> private void Start(MarshaledResultSetter callback, Action action, bool verbose, params object[] args) { CheckState(BaZicInterpreterState.Ready, BaZicInterpreterState.Idle, BaZicInterpreterState.Stopped, BaZicInterpreterState.StoppedWithError); ChangeState(this, new BaZicInterpreterStateChangeEventArgs(BaZicInterpreterState.Preparing)); _programArguments = args; Verbose = verbose; DebugInfos = null; Error = null; var currentCulture = LocalizationHelper.GetCurrentCulture(); _mainInterpreterTask = Task.Run(() => { _mainInterpreterThread = Thread.CurrentThread; LocalizationHelper.SetCurrentCulture(currentCulture, false, false); RuntimeHelpers.EnsureSufficientExecutionStack(); GCSettings.LatencyMode = GCLatencyMode.LowLatency; try { action(); } catch (Exception exception) { CoreHelper.ReportException(exception); if (!_ignoreException) { ChangeState(this, new UnexpectedException(exception)); } _ignoreException = false; } finally { GC.Collect(); GC.WaitForPendingFinalizers(); } }); _mainInterpreterTask.ContinueWith((task) => { callback.NotifyEndTask(); if (!_releaseModeForced) { RunningStateManager.UpdateState(); } _mainInterpreterThread = null; }); }