Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/26/08 11:32:58 (16 years ago)
Author:
gkronber
Message:

fixed #138 (Starting multiple applications concurrently causes some of the splashscreens to stay visible) in 3.1 branch

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3.1/sources/HeuristicLab/SplashScreen.cs

    r17 r599  
    3030namespace HeuristicLab {
    3131  public partial class SplashScreen : Form {
    32     private int myDisplayTime = 1000;
    33     public int DisplayTime {
    34       get { return (myDisplayTime); }
    35       set {
    36         if(value > 0) {
    37           myDisplayTime = value;
    38           waitTimer.Interval = value;
    39         }
    40       }
    41     }
     32    private const int FADE_INTERVAL = 50;
     33    private System.Timers.Timer fadeTimer;
     34    private int initialInterval;
     35    private object bigLock = new object();
     36    private bool closing = false;
    4237
    4338    public SplashScreen() {
     
    7772        companyLabel.Text = "-";
    7873      }
    79       waitTimer.Start();
    8074    }
    8175
    82     public SplashScreen(int displayTime, string initialText)
     76    public SplashScreen(int initialInterval, string initialText)
    8377      : this() {
    84       waitTimer.Stop();
    85       DisplayTime = displayTime;
    86       waitTimer.Start();
     78      this.initialInterval = initialInterval;
    8779      infoLabel.Text = initialText;
    8880    }
     
    9385
    9486    public void Manager_Action(object sender, PluginManagerActionEventArgs e) {
    95       if(!this.Disposing && !this.IsDisposed) {
    96         waitTimer.Stop();
    97         string info;
    98         if(e.Action == PluginManagerAction.Initializing) info = "Initializing ...";
    99         else if(e.Action == PluginManagerAction.InitializingPlugin) info = "Initializing Plugin " + e.Id + " ...";
    100         else if(e.Action == PluginManagerAction.InitializedPlugin) info = "Initializing Plugin " + e.Id + " ... Initialized";
    101         else if(e.Action == PluginManagerAction.Initialized) info = "Initialization Completed";
    102         else {
    103           if(e.Id != null) info = e.Action.ToString() + "   (" + e.Id + ")";
    104           else info = e.Action.ToString();
    105         }
    106         SetInfoText(info);
    107         Application.DoEvents();
    108         waitTimer.Start();
     87      string info;
     88      if(e.Action == PluginManagerAction.Initializing) info = "Initializing ...";
     89      else if(e.Action == PluginManagerAction.InitializingPlugin) info = "Initializing Plugin " + e.Id + " ...";
     90      else if(e.Action == PluginManagerAction.InitializedPlugin) info = "Initializing Plugin " + e.Id + " ... Initialized";
     91      else if(e.Action == PluginManagerAction.Initialized) {
     92        info = "Initialization Completed";
     93        fadeTimer = new System.Timers.Timer();
     94        fadeTimer.SynchronizingObject = this;
     95        fadeTimer.Elapsed += new System.Timers.ElapsedEventHandler(fadeTimer_Elapsed);
     96        fadeTimer.Interval = initialInterval;
     97        fadeTimer.AutoReset = true;
     98        fadeTimer.Start();
     99      } else {
     100        if(e.Id != null) info = e.Action.ToString() + "   (" + e.Id + ")";
     101        else info = e.Action.ToString();
     102      }
     103      SetInfoText(info);
     104      Application.DoEvents();
     105    }
     106
     107    private void fadeTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) {
     108      fadeTimer.Stop();
     109      if(InvokeRequired) {
     110        Invoke((MethodInvoker)UpdateOpacity);
     111      } else {
     112        UpdateOpacity();
    109113      }
    110114    }
    111115
    112     private void waitTimer_Tick(object sender, System.EventArgs e) {
    113       if(!this.Disposing && !this.IsDisposed) {
    114         waitTimer.Stop();
    115         fadeTimer.Start();
    116       }
    117     }
    118 
    119     private void fadeTimer_Tick(object sender, EventArgs e) {
    120       if(InvokeRequired) {
    121         Invoke((MethodInvoker)delegate() {
    122           if(Opacity > 0.9) {
    123             Opacity = 0.9;
    124           } else if(this.Opacity > 0) {
    125             Opacity -= 0.1;
    126           } else {
    127             Opacity = 0;
    128             fadeTimer.Stop();
    129             Close();
    130           }
    131         });
    132       } else {
     116    private void UpdateOpacity() {
     117      lock(bigLock) {
     118        if(closing) return;
    133119        if(Opacity > 0.9) {
    134120          Opacity = 0.9;
     121          fadeTimer.Interval = FADE_INTERVAL;
     122          fadeTimer.Start();
    135123        } else if(this.Opacity > 0) {
    136124          Opacity -= 0.1;
     125          fadeTimer.Start();
    137126        } else {
    138127          Opacity = 0;
    139           fadeTimer.Stop();
    140128          Close();
    141129        }
    142130      }
    143131    }
    144 
    145132
    146133    private void SplashScreen_FormClosing(object sender, FormClosingEventArgs e) {
     
    149136
    150137    private void closeButton_Click(object sender, EventArgs e) {
    151       waitTimer.Stop();
    152       Close();
     138      lock(bigLock) {
     139        closing = true;
     140        if(fadeTimer != null) fadeTimer.Stop();
     141        Close();
     142      }
    153143    }
    154144  }
Note: See TracChangeset for help on using the changeset viewer.