How to close splash screen?

2

I've developed a splash screen for my application. It is working perfectly, it opens and directs to Form2 . But I realized that when I close Form2 , I have to stop debugging through Visual Studio, as it looks like splash is active. I used the following code in method Timer1 :

private void timer1_Tick(object sender, EventArgs e)
        {
            if(progressBar1.Value < 100){
                progressBar1.Value = progressBar1.Value + 2;
            }
            else
            {
                timer1.Enabled = false;
                this.Visible = false;
                Form1 direcionar = new Form1();
                direcionar.ShowDialog();
            }
        }

My concern is that when I install the app on another computer, the splash will remain active in memory, if so, how would I do that when I close the app, the splash is also closed and not just invisible. >

See the image below. I closed the app, but it is still debugging.

    
asked by anonymous 24.08.2015 / 14:26

2 answers

3

Just give this.Close() (assuming the splash screen is this ) the moment you think it should. The method close() makes the form available to be removed from memory. You do not need anything else. If this variable is no longer referenced elsewhere, at the appropriate time, the garbage collector will free all resources that have been allocated to it. The .Net has managed memory and you do not have to worry about these things, just use right: ensure that the resource has been terminated as shown above and have no further references to it that can keep it alive even though it is not being shown. It would look something like this:

private void timer1_Tick(object sender, EventArgs e) {
        if(progressBar1.Value < 100){
            progressBar1.Value = progressBar1.Value + 2;
        } else {
            timer1.Enabled = false;
            this.Close();
            Form1 direcionar = new Form1(); //isto provavelmente não pode estar aqui.
            direcionar.ShowDialog();
        }
    }

But this alone will probably not solve the memory consumption because this object will be active preventing it from being collected. Also, I do not remember the consequences, but if you terminate a form that created another or will give error or will keep the object active.

The way you are building the application on splash screen will be your main screen and will never be actually destroyed or will be destroyed by terminating the application. Or do you reverse this situation, ie create a main form and temporarily call the splash screen inside this form or what I would do is separate the two forms, something like this (simpler speaking):

>
Application.Run(new SplashForm());
Application.Run(new MainForm());

A answer in the OS with another way of doing the same. Net already has the infrastructure to do the job.

    
24.08.2015 / 14:32
0

You can put this code " Application.Exit(); " in the FormClosed event and in FormClosing to kill your Splash application once and for all.

    
17.01.2017 / 15:12