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
{
///
/// The main entry point for the application.
///
[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();
}
}
Sam HobbsPosted Oct 21, 2011, 9:00 AM
VulpesPosted Oct 21, 2011, 5:33 AM
Yves GilsonPosted Oct 21, 2011, 3:54 AM
Sam HobbsPosted Oct 20, 2011, 2:13 PM
Application.SetCompatibleTextRenderingDefault(false);
ApplicationContext Context = new ApplicationContext(new Main());
new Splash().Show();
Application.Run(Context);
You can of course create a another thread to do other things; that would work the same. If you want to you can set the main form to be not visible initially and then make it visible when the splash screen closes. An easy way to do that is to create a constructor for the Splash class and pass the main form instance that way, or make a property of the Splash class or there are other possibilities.
VulpesPosted Oct 20, 2011, 11:30 AM
Yves GilsonPosted Oct 20, 2011, 10:54 AM
VulpesPosted Oct 20, 2011, 10:43 AM