7
Reply

SplashScreen issue, main form goes Backward when Splashscreen disposes

Yves Gilson

Yves Gilson

Oct 20 2011 10:08 AM
3.7k
Hi,

I am facing a strange behavior that I cannot understand

As my application loads a lot of dll before starting, I wanted to show a splashscreen when loading.
The splashscreen forms disposes when the main form is fully loaded, and when it disposes, the main form goes behind the explorer that run the application.

I made a simplified code here, 2 forms : Main and Splash
The application creates a thread that displays the splashscreen, waits 2 sec, and runs the Main form.
The splashscreen has a timer of 5 sec, when it elapsed, it closes itself.

The result is, when I start the application from the VStudio environment.. it runs properly, when it runs from explorer or something else (like totalcmd for my personal use) the application shows the splashscreen (Topmost = true) for 2 seconds, then appears just behind it the main form. after 3 seconds the splashscreen closes and the main form disappears, because it goes behind the explorer that run it.

you can find the full test solution attached.

what am i doing wrong ?

yves

Programs.cs
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>

        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            Thread splashThread = new Thread(new ThreadStart(ShowSplashScreen));
            splashThread.Start();

            Thread.Sleep(2000);
            Application.Run(new Main());
        }

        static void ShowSplashScreen()
        {
            Application.Run(new Splash());
        }
    }

Splash.cs
    public partial class Splash : Form
    {
        public Splash()
        {
            InitializeComponent();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            Close();
        }
    }

Main.cs
    public partial class Main : Form
    {
        public Main()
        {
            InitializeComponent();
        }
    }




Attachment: splashscreentest.zip

Answers (7)