Free cookie consent management tool by TermsFeed Policy Generator

Changeset 3113


Ignore:
Timestamp:
03/19/10 12:54:40 (15 years ago)
Author:
gkronber
Message:

Changed starter form to instantiate only one splash screen and show and hide it as required. #183 (Splash screen sometimes causes ObjectDisposedException)

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

Legend:

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

    r2922 r3113  
    3636    private int initialInterval;
    3737    private PluginManager manager;
    38 
     38    private bool fadeOutForced;
    3939    internal SplashScreen() {
    4040      InitializeComponent();
    4141    }
    4242
    43     internal SplashScreen(PluginManager manager, int initialInterval, string initialText)
     43    internal SplashScreen(PluginManager manager, int initialInterval)
    4444      : this() {
    4545      this.initialInterval = initialInterval;
     
    5353      manager.PluginUnloaded += new EventHandler<PluginInfrastructureEventArgs>(manager_PluginUnloaded);
    5454
    55       infoLabel.Text = initialText;
    5655      titleLabel.Text = Application.ProductName;
    5756      versionLabel.Text = "Version " + Application.ProductVersion;
     
    9695    }
    9796
     97    public void Show(string initialText) {
     98      if (InvokeRequired) Invoke((Action<string>)Show, initialText);
     99      else {
     100        Opacity = 1;
     101        infoLabel.Text = initialText;
     102        fadeOutForced = false;
     103        ResetFadeTimer();
     104        Show();
     105      }
     106    }
     107
     108    private void ResetFadeTimer() {
     109      // wait initialInterval again for the first tick
     110      fadeTimer.Stop();
     111      fadeTimer.Interval = initialInterval;
     112      fadeTimer.Start();
     113    }
     114
     115
    98116    private void SetInfoText(string text) {
    99117      if (InvokeRequired) Invoke((Action<string>)SetInfoText, text);
     
    107125        Invoke((Action<string>)UpdateMessage, msg);
    108126      } else {
    109         ResetFadeTimer();
     127        // when the user forced a fade-out (by closing the splashscreen)
     128        // don't reset the fadeTimer
     129        if (!fadeOutForced) {
     130          ResetFadeTimer();
     131        }
    110132        SetInfoText(msg);
    111133        Application.DoEvents(); // force immediate update of splash screen control
     
    113135    }
    114136
    115     private void ResetFadeTimer() {
    116       fadeTimer.Stop(); fadeTimer.Start();
     137    // each tick of the timer reduce opacity and restart timer
     138    private void fadeTimer_Elapsed(object sender, EventArgs e) {
     139      FadeOut();
    117140    }
    118141
    119     private void fadeTimer_Elapsed(object sender, EventArgs e) {
    120       FadeOutAndClose();
    121     }
    122 
    123     private void FadeOutAndClose() {
     142    // reduces opacity of the splashscreen one step and restarts the fade-timer
     143    private void FadeOut() {
    124144      fadeTimer.Stop();
    125145      fadeTimer.Interval = FADE_INTERVAL;
     
    130150        Opacity = 0;
    131151        fadeTimer.Stop();
    132         fadeTimer.Dispose();
    133         // remove event before calling close
    134         manager.ApplicationStarted -= new EventHandler<PluginInfrastructureEventArgs>(manager_ApplicationStarted);
    135         manager.ApplicationStarting -= new EventHandler<PluginInfrastructureEventArgs>(manager_ApplicationStarting);
    136         manager.Initializing -= new EventHandler<PluginInfrastructureEventArgs>(manager_Initialized);
    137         manager.Initialized -= new EventHandler<PluginInfrastructureEventArgs>(manager_Initializing);
    138         manager.PluginLoaded -= new EventHandler<PluginInfrastructureEventArgs>(manager_PluginLoaded);
    139         manager.PluginUnloaded -= new EventHandler<PluginInfrastructureEventArgs>(manager_PluginUnloaded);
    140         Close();
     152        Hide();
    141153      }
    142154    }
    143155
     156    // force fade out
    144157    private void closeButton_Click(object sender, EventArgs e) {
    145       FadeOutAndClose();
     158      fadeOutForced = true;
     159      FadeOut();
    146160    }
    147161  }
  • trunk/sources/HeuristicLab.PluginInfrastructure/Starter/StarterForm.cs

    r3092 r3113  
    4545    private bool abortRequested;
    4646    private PluginManager pluginManager;
     47    private SplashScreen splashScreen;
    4748
    4849    /// <summary>
     
    5657      string pluginPath = Path.GetFullPath(Application.StartupPath);
    5758      pluginManager = new PluginManager(pluginPath);
    58       SplashScreen splashScreen = new SplashScreen(pluginManager, 1000, "Loading HeuristicLab...");
    59       splashScreen.Show();
     59      splashScreen = new SplashScreen(pluginManager, 1000);
     60      splashScreen.Show("Loading HeuristicLab...");
    6061
    6162      pluginManager.DiscoverAndCheckPlugins();
     
    129130
    130131    private void StartApplication(ApplicationDescription app) {
    131       SplashScreen splashScreen = new SplashScreen(pluginManager, 2000, "Loading " + app.Name);
    132       splashScreen.Show();
     132      //new SplashScreen(pluginManager, 2000, );
     133      splashScreen.Show("Loading " + app.Name);
    133134      Thread t = new Thread(delegate() {
    134135        bool stopped = false;
Note: See TracChangeset for help on using the changeset viewer.