internal void OnExit() { Logger.Info("Shutting down..."); Parallel.Invoke( new ParallelOptions() { MaxDegreeOfParallelism = 10 }, async() => await RestServer.ShutdownServer().ConfigureAwait(false), () => ModuleLoader.ExecuteActionOnType <IEvent>((e) => e.OnShutdownRequested()), () => ModuleLoader.ExecuteActionOnType <IAsyncEvent>(async(e) => await e.OnShutdownRequested().ConfigureAwait(false)), () => Interpreter.ExitShell(), () => RestServer.Dispose(), () => Controller.Dispose(), () => JobManager.RemoveAllJobs(), () => JobManager.Stop(), () => InternalConfigWatcher.StopWatcher(), () => InternalModuleWatcher.StopWatcher(), () => ModuleLoader?.OnCoreShutdown(), async() => await Config.SaveAsync().ConfigureAwait(false) ); Logger.Trace("Finished exit tasks."); }