Free cookie consent management tool by TermsFeed Policy Generator

Changeset 241 for trunk


Ignore:
Timestamp:
05/13/08 18:58:34 (17 years ago)
Author:
gkronber
Message:

Stability improvement.
also makes debugging easier (related to #149). Should be merged into the trunk after testing.

  • added exception handling in PluginManager to graciously unload AppDomains when an uncaught exception is occurred
  • added exception handling in the starter-form to display an error message-box
Location:
trunk/sources
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.PluginInfrastructure/PluginManager.cs

    r29 r241  
    103103      setup.PrivateBinPath = pluginDir;
    104104      AppDomain applicationDomain = AppDomain.CreateDomain(appInfo.Name + " AppDomain", null, setup);
    105 
    106       Runner remoteRunner = (Runner)applicationDomain.CreateInstanceAndUnwrap("HeuristicLab.PluginInfrastructure", "HeuristicLab.PluginInfrastructure.Runner");
    107       NotifyListeners(PluginManagerAction.Initializing, "All plugins");
    108       remoteRunner.LoadPlugins(remoteLoader.ActivePlugins);
    109       NotifyListeners(PluginManagerAction.Initialized, "All plugins");
    110       remoteRunner.Run(appInfo);
    111 
    112       AppDomain.Unload(applicationDomain);
     105      try {
     106        Runner remoteRunner = (Runner)applicationDomain.CreateInstanceAndUnwrap("HeuristicLab.PluginInfrastructure", "HeuristicLab.PluginInfrastructure.Runner");
     107        NotifyListeners(PluginManagerAction.Initializing, "All plugins");
     108        remoteRunner.LoadPlugins(remoteLoader.ActivePlugins);
     109        NotifyListeners(PluginManagerAction.Initialized, "All plugins");
     110        remoteRunner.Run(appInfo);
     111      } catch(Exception ex) {
     112        // can't handle exception here -> rethrow
     113        throw new ApplicationException("Exception in "+appInfo.Name, ex);
     114      } finally {
     115        // make sure domain is unloaded in all cases
     116        AppDomain.Unload(applicationDomain);
     117      }
    113118    }
    114119
  • trunk/sources/HeuristicLab/MainForm.cs

    r209 r241  
    9494          PluginManager.Manager.Action += new PluginManagerActionEventHandler(splashScreen.Manager_Action);
    9595          Thread t = new Thread(delegate() {
    96             PluginManager.Manager.Run(app);
     96            try {
     97              PluginManager.Manager.Run(app);
     98            } catch(Exception ex) {
     99              ShowErrorMessageBox(ex);
     100            }
    97101          });
    98102          t.SetApartmentState(ApartmentState.STA); // needed for the AdvancedOptimizationFrontent
     
    122126    }
    123127
     128    public void ShowErrorMessageBox(Exception ex) {
     129      MessageBox.Show(BuildErrorMessage(ex),
     130                      "Error - " + ex.GetType().Name,
     131                      MessageBoxButtons.OK,
     132                      MessageBoxIcon.Error);
     133    }
     134    private string BuildErrorMessage(Exception ex) {
     135      StringBuilder sb = new StringBuilder();
     136      sb.Append("Sorry, but something went wrong!\n\n" + ex.Message + "\n\n" + ex.StackTrace);
     137
     138      while(ex.InnerException != null) {
     139        ex = ex.InnerException;
     140        sb.Append("\n\n-----\n\n" + ex.Message + "\n\n" + ex.StackTrace);
     141      }
     142      return sb.ToString();
     143    }
    124144  }
    125145}
Note: See TracChangeset for help on using the changeset viewer.