From 937d27ae9d6aa571ab9327f138bfba1b84c158db Mon Sep 17 00:00:00 2001 From: LukePulverenti Luke Pulverenti luke pulverenti Date: Sun, 19 Aug 2012 16:38:31 -0400 Subject: One async call leads to another, and another, all the way up the call stack... --- MediaBrowser.Common/Kernel/BaseKernel.cs | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) (limited to 'MediaBrowser.Common/Kernel/BaseKernel.cs') diff --git a/MediaBrowser.Common/Kernel/BaseKernel.cs b/MediaBrowser.Common/Kernel/BaseKernel.cs index 7b6f6844c..5b2f97ced 100644 --- a/MediaBrowser.Common/Kernel/BaseKernel.cs +++ b/MediaBrowser.Common/Kernel/BaseKernel.cs @@ -2,17 +2,16 @@ using System.Collections.Generic; using System.ComponentModel.Composition; using System.ComponentModel.Composition.Hosting; -using System.Configuration; using System.IO; using System.Linq; using System.Reflection; +using System.Threading.Tasks; using MediaBrowser.Common.Configuration; using MediaBrowser.Common.Logging; using MediaBrowser.Common.Net; using MediaBrowser.Common.Plugins; using MediaBrowser.Common.Serialization; using MediaBrowser.Model.Progress; -using System.Threading.Tasks; namespace MediaBrowser.Common.Kernel { @@ -93,6 +92,8 @@ namespace MediaBrowser.Common.Kernel /// protected void ReloadComposableParts() { + DisposeComposableParts(); + // Gets all plugin assemblies by first reading all bytes of the .dll and calling Assembly.Load against that // This will prevent the .dll file from getting locked, and allow us to replace it when needed IEnumerable pluginAssemblies = Directory.GetFiles(ApplicationPaths.PluginsPath, "*.dll", SearchOption.AllDirectories).Select(f => Assembly.Load(File.ReadAllBytes((f)))); @@ -203,10 +204,33 @@ namespace MediaBrowser.Common.Kernel /// public virtual void Dispose() { + DisposeComposableParts(); DisposeHttpServer(); DisposeLogger(); } + /// + /// Disposes all objects gathered through MEF composable parts + /// + protected virtual void DisposeComposableParts() + { + DisposePlugins(); + } + + /// + /// Disposes all plugins + /// + private void DisposePlugins() + { + if (Plugins != null) + { + foreach (BasePlugin plugin in Plugins) + { + plugin.Dispose(); + } + } + } + /// /// Disposes the current HttpServer /// -- cgit v1.2.3