Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/28/19 08:58:43 (6 years ago)
Author:
jkarder
Message:

#2961: merged r16909 into stable

Location:
stable
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.PluginInfrastructure/3.3/SandboxApplicationManager.cs

    r15584 r16989  
    7171      loadedAssemblies = new Dictionary<string, Assembly>();
    7272      loadedPlugins = new List<IPlugin>();
     73
     74      AppDomain.CurrentDomain.DomainUnload += CurrentDomain_DomainUnload;
     75    }
     76
     77    /// <summary>
     78    /// The sandbox application manager can also be used to load plugins even when no actual application is executed.
     79    /// In such cases, plugins that have been loaded also have to be unloaded again before the application domain is unloaded.
     80    /// </summary>
     81    private void CurrentDomain_DomainUnload(object sender, EventArgs e) {
     82      UnloadPlugins();
    7383    }
    7484
     
    111121
    112122    /// <summary>
     123    /// Unloads the <paramref name="plugins"/> that were loaded into this application domain.
     124    /// </summary>
     125    private void UnloadPlugins() {
     126      // unload plugins in reverse order
     127      foreach (var plugin in loadedPlugins.Reverse<IPlugin>()) {
     128        plugin.OnUnload();
     129      }
     130      loadedPlugins.Clear(); // remove all plugins once unloaded
     131
     132      foreach (var desc in PluginDescriptionIterator.IterateDependenciesBottomUp(plugins.Where(x => x.PluginState != PluginState.Disabled))) {
     133        desc.Unload();
     134        OnPluginUnloaded(new PluginInfrastructureEventArgs(desc));
     135      }
     136      plugins.Clear(); // remove all plugin descriptions once unloaded
     137    }
     138
     139    /// <summary>
    113140    /// Runs the application declared in <paramref name="appInfo"/>.
    114141    /// This is a synchronous call. When the application is terminated all plugins are unloaded.
     
    119146      try {
    120147        runnablePlugin.Run(args);
    121       }
    122       finally {
    123         // unload plugins in reverse order
    124         foreach (var plugin in loadedPlugins.Reverse<IPlugin>()) {
    125           plugin.OnUnload();
    126         }
    127         foreach (var desc in PluginDescriptionIterator.IterateDependenciesBottomUp(plugins.Where(x => x.PluginState != PluginState.Disabled))) {
    128           desc.Unload();
    129           OnPluginUnloaded(new PluginInfrastructureEventArgs(desc));
    130         }
     148      } finally {
     149        UnloadPlugins();
    131150      }
    132151    }
Note: See TracChangeset for help on using the changeset viewer.