Pergunta

I have some code in my main form which loads another form as soon as the project launches:

private void Form1_Load(object sender, EventArgs e)
    {
        Updating upd = new Updating();
        upd.Show();
    }

This new form (currently) just contains this code:

private void Updating_Load(object sender, EventArgs e)
    {
        this.BackgroundImage = Properties.Resources.updating1;
        Stopwatch dw = new Stopwatch();
        dw.Start();
        bool qsdf = true;
        while (qsdf)
        {
            if (dw.ElapsedMilliseconds >= 3000) qsdf = false; dw.Stop();
        }    
        this.BackgroundImage = Properties.Resources.updating2;
        Stopwatch sw = new Stopwatch();
        sw.Start();
        qsdf = true;
        while (qsdf)
        {
            if (sw.ElapsedMilliseconds >= 3000) qsdf = false; sw.Stop();
        }
        this.Close();

Now, for some reason, the form being called (form called Updating) doesn't show at all. All that currently happens is I get nothing at all for 6 seconds (as noted by the stopwatch) before I get my main form to show, not seeing the Updating form even once.

Note: this is the code in my Updating.Designer.cs which draws all the components:

this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.BackgroundImage = global::BossCraftLauncher.Properties.Resources.updating1;
        this.ClientSize = new System.Drawing.Size(300, 100);
        this.ControlBox = false;
        this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
        this.MaximizeBox = false;
        this.MinimizeBox = false;
        this.Name = "Updating";
        this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
        this.Text = "BCL Update";
        this.Load += new System.EventHandler(this.Updating_Load);
        this.ResumeLayout(false);
Foi útil?

Solução

Your loop is blocking the UI thread. As the load event fires.. your loop stops it from continuing it's message queue.

The easiest option for you (as you're using WinForms) is to use a Timer control and put your code in the Tick event.

Outras dicas

Why are you closing the Updating form on the updating_Load?? "this.Close();" If you write the close() function in the formload,after loading the screen the form will be closed.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top