From 3acfd73d86a06fc024e4293e37aa4e0fe226409c Mon Sep 17 00:00:00 2001 From: LukePulverenti Date: Sun, 10 Mar 2013 01:45:16 -0500 Subject: fixed scheduled tasks firing too early --- MediaBrowser.ServerApplication/ApplicationHost.cs | 50 +++++++++++++---------- 1 file changed, 28 insertions(+), 22 deletions(-) (limited to 'MediaBrowser.ServerApplication/ApplicationHost.cs') diff --git a/MediaBrowser.ServerApplication/ApplicationHost.cs b/MediaBrowser.ServerApplication/ApplicationHost.cs index e156c465b..d5a505792 100644 --- a/MediaBrowser.ServerApplication/ApplicationHost.cs +++ b/MediaBrowser.ServerApplication/ApplicationHost.cs @@ -127,23 +127,21 @@ namespace MediaBrowser.ServerApplication /// /// The HTTP server. private IHttpServer HttpServer { get; set; } - + /// - /// Inits this instance. + /// Runs the startup tasks. /// /// Task. - public override async Task Init() + protected override async Task RunStartupTasks() { - await base.Init().ConfigureAwait(false); + // Do these before allowing the base method to run, which will invoke startup scheduled tasks + await ServerKernel.LoadRepositories(ServerConfigurationManager).ConfigureAwait(false); - Task.Run(async () => - { - await ServerKernel.LoadRepositories(ServerConfigurationManager).ConfigureAwait(false); + await base.RunStartupTasks().ConfigureAwait(false); - DirectoryWatchers.Start(); + DirectoryWatchers.Start(); - Parallel.ForEach(GetExports(), entryPoint => entryPoint.Run()); - }); + Parallel.ForEach(GetExports(), entryPoint => entryPoint.Run()); } /// @@ -206,13 +204,15 @@ namespace MediaBrowser.ServerApplication ServerKernel.FFMpegManager = new FFMpegManager(ServerKernel, ZipClient, JsonSerializer, ProtobufSerializer, LogManager, ApplicationPaths); ServerKernel.ImageManager = new ImageManager(ServerKernel, ProtobufSerializer, LogManager.GetLogger("ImageManager"), ApplicationPaths); - ServerKernel.UserDataRepositories = GetExports(); - ServerKernel.UserRepositories = GetExports(); - ServerKernel.DisplayPreferencesRepositories = GetExports(); - ServerKernel.ItemRepositories = GetExports(); - ServerKernel.WeatherProviders = GetExports(); - ServerKernel.ImageEnhancers = GetExports().OrderBy(e => e.Priority).ToArray(); - ServerKernel.StringFiles = GetExports(); + Parallel.Invoke( + () => ServerKernel.UserDataRepositories = GetExports(), + () => ServerKernel.UserRepositories = GetExports(), + () => ServerKernel.DisplayPreferencesRepositories = GetExports(), + () => ServerKernel.ItemRepositories = GetExports(), + () => ServerKernel.WeatherProviders = GetExports(), + () => ServerKernel.ImageEnhancers = GetExports().OrderBy(e => e.Priority).ToArray(), + () => ServerKernel.StringFiles = GetExports() + ); } /// @@ -238,14 +238,20 @@ namespace MediaBrowser.ServerApplication { base.FindParts(); - HttpServer.Init(GetExports(false)); + Parallel.Invoke( + + () => + { + HttpServer.Init(GetExports(false)); - ServerManager.AddWebSocketListeners(GetExports(false)); - ServerManager.Start(); + ServerManager.AddWebSocketListeners(GetExports(false)); + ServerManager.Start(); + }, - LibraryManager.AddParts(GetExports(), GetExports(), GetExports(), GetExports(), GetExports()); + () => LibraryManager.AddParts(GetExports(), GetExports(), GetExports(), GetExports(), GetExports()), - ProviderManager.AddMetadataProviders(GetExports().OrderBy(e => e.Priority).ToArray()); + () => ProviderManager.AddMetadataProviders(GetExports().OrderBy(e => e.Priority).ToArray()) + ); } /// -- cgit v1.2.3