Free cookie consent management tool by TermsFeed Policy Generator

Changeset 4515


Ignore:
Timestamp:
09/27/10 14:01:04 (14 years ago)
Author:
gkronber
Message:

Added work-around for race-condition in SplashScreen:

  • deregister events correctly
  • catch ObjectDisposedException in UpdateMessage in splash-screen

#795

Location:
trunk/sources/HeuristicLab.PluginInfrastructure/3.3/Starter
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.PluginInfrastructure/3.3/Starter/SplashScreen.cs

    r4482 r4515  
    3232    private Timer fadeTimer;
    3333    private int initialInterval;
     34    private PluginManager pluginManager;
    3435
    3536    internal SplashScreen() {
     
    4041      : this() {
    4142      this.initialInterval = initialInterval;
     43      this.pluginManager = manager;
    4244
    43       manager.ApplicationStarted += new EventHandler<PluginInfrastructureEventArgs>(manager_ApplicationStarted);
    44       manager.ApplicationStarting += new EventHandler<PluginInfrastructureEventArgs>(manager_ApplicationStarting);
    45       manager.Initializing += new EventHandler<PluginInfrastructureEventArgs>(manager_Initializing);
    46       manager.Initialized += new EventHandler<PluginInfrastructureEventArgs>(manager_Initialized);
    47       manager.PluginLoaded += new EventHandler<PluginInfrastructureEventArgs>(manager_PluginLoaded);
    48       manager.PluginUnloaded += new EventHandler<PluginInfrastructureEventArgs>(manager_PluginUnloaded);
     45      RegisterPluginManagerEventHandlers();
    4946
    5047      FileVersionInfo pluginInfrastructureVersion = FileVersionInfo.GetVersionInfo(GetType().Assembly.Location);
     
    6057    }
    6158
    62     void manager_PluginUnloaded(object sender, PluginInfrastructureEventArgs e) {
    63       UpdateMessage("Unloaded " + e.Entity);
     59    #region events
     60    private void RegisterPluginManagerEventHandlers() {
     61      pluginManager.ApplicationStarted += new EventHandler<PluginInfrastructureEventArgs>(manager_ApplicationStarted);
     62      pluginManager.ApplicationStarting += new EventHandler<PluginInfrastructureEventArgs>(manager_ApplicationStarting);
     63      pluginManager.Initializing += new EventHandler<PluginInfrastructureEventArgs>(manager_Initializing);
     64      pluginManager.Initialized += new EventHandler<PluginInfrastructureEventArgs>(manager_Initialized);
     65      pluginManager.PluginLoaded += new EventHandler<PluginInfrastructureEventArgs>(manager_PluginLoaded);
     66      pluginManager.PluginUnloaded += new EventHandler<PluginInfrastructureEventArgs>(manager_PluginUnloaded);
    6467    }
    6568
    66     void manager_PluginLoaded(object sender, PluginInfrastructureEventArgs e) {
    67       UpdateMessage("Loaded " + e.Entity);
     69    private void DeregisterPluginManagerEventHandlers() {
     70      pluginManager.ApplicationStarted -= new EventHandler<PluginInfrastructureEventArgs>(manager_ApplicationStarted);
     71      pluginManager.ApplicationStarting -= new EventHandler<PluginInfrastructureEventArgs>(manager_ApplicationStarting);
     72      pluginManager.Initializing -= new EventHandler<PluginInfrastructureEventArgs>(manager_Initializing);
     73      pluginManager.Initialized -= new EventHandler<PluginInfrastructureEventArgs>(manager_Initialized);
     74      pluginManager.PluginLoaded -= new EventHandler<PluginInfrastructureEventArgs>(manager_PluginLoaded);
     75      pluginManager.PluginUnloaded -= new EventHandler<PluginInfrastructureEventArgs>(manager_PluginUnloaded);
    6876    }
    6977
    70     void manager_Initialized(object sender, PluginInfrastructureEventArgs e) {
    71       UpdateMessage("Initialized");
     78    private void manager_PluginUnloaded(object sender, PluginInfrastructureEventArgs e) {
     79      SafeUpdateMessage("Unloaded " + e.Entity);
    7280    }
    7381
    74     void manager_Initializing(object sender, PluginInfrastructureEventArgs e) {
    75       UpdateMessage("Initializing");
     82    private void manager_PluginLoaded(object sender, PluginInfrastructureEventArgs e) {
     83      SafeUpdateMessage("Loaded " + e.Entity);
    7684    }
    7785
    78     void manager_ApplicationStarting(object sender, PluginInfrastructureEventArgs e) {
    79       UpdateMessage("Starting " + e.Entity);
     86    private void manager_Initialized(object sender, PluginInfrastructureEventArgs e) {
     87      SafeUpdateMessage("Initialized");
    8088    }
    8189
    82     void manager_ApplicationStarted(object sender, PluginInfrastructureEventArgs e) {
    83       UpdateMessage("Started " + e.Entity);
     90    private void manager_Initializing(object sender, PluginInfrastructureEventArgs e) {
     91      SafeUpdateMessage("Initializing");
    8492    }
     93
     94    private void manager_ApplicationStarting(object sender, PluginInfrastructureEventArgs e) {
     95      SafeUpdateMessage("Starting " + e.Entity);
     96    }
     97
     98    private void manager_ApplicationStarted(object sender, PluginInfrastructureEventArgs e) {
     99      SafeUpdateMessage("Started " + e.Entity);
     100    }
     101    // called from event handlers
     102    private void SafeUpdateMessage(string msg) {
     103      try {
     104        Invoke((Action<string>)UpdateMessage, msg);
     105      }
     106      catch (ObjectDisposedException) { }
     107    }
     108
     109    // each tick of the timer reduce opacity and restart timer
     110    private void fadeTimer_Elapsed(object sender, EventArgs e) {
     111      // only called from local timer: no need to invoke here
     112      FadeOut();
     113    }
     114    #endregion
    85115
    86116    public void Show(string initialText) {
     
    95125
    96126    public void Show(IWin32Window owner, string initialText) {
    97       if (InvokeRequired) Invoke((Action<string>)Show, initialText);
     127      if (InvokeRequired) Invoke((Action<IWin32Window, string>)Show, owner, initialText);
    98128      else {
    99129        Opacity = 1;
     
    111141    }
    112142
    113 
    114     private void SetInfoText(string text) {
    115       if (InvokeRequired) Invoke((Action<string>)SetInfoText, text);
    116       else {
    117         infoLabel.Text = text;
    118       }
    119     }
    120 
    121143    private void UpdateMessage(string msg) {
    122       if (InvokeRequired) {
    123         Invoke((Action<string>)UpdateMessage, msg);
    124       } else {
    125         ResetFadeTimer();
    126         SetInfoText(msg);
    127         Application.DoEvents(); // force immediate update of splash screen control
    128       }
    129     }
    130 
    131     // each tick of the timer reduce opacity and restart timer
    132     private void fadeTimer_Elapsed(object sender, EventArgs e) {
    133       FadeOut();
     144      ResetFadeTimer();
     145      infoLabel.Text = msg;
     146      Application.DoEvents(); // force immediate update of splash screen control
    134147    }
    135148
     
    147160      }
    148161    }
     162
     163    protected override void OnClosing(System.ComponentModel.CancelEventArgs e) {
     164      // deregister events when form is closing
     165      DeregisterPluginManagerEventHandlers();
     166      base.OnClosing(e);
     167    }
    149168  }
    150169}
  • trunk/sources/HeuristicLab.PluginInfrastructure/3.3/Starter/StarterForm.cs

    r4482 r4515  
    176176
    177177    private void MainForm_FormClosing(object sender, FormClosingEventArgs e) {
     178      splashScreen.Close();
    178179      abortRequested = true;
    179180    }
Note: See TracChangeset for help on using the changeset viewer.