Nothing comes of spawning a thread if your goal is to get a splash screen as quickly as possible.
There are several ways to make screensavers, and the more complicated one is mentioned here , but this is a simple method that I used with complete success:
Just make sure you download and display the splash form first , and then continue to download your application while the user looks at the pretty splash screen. When mainform is loading, it can close the splash right before it shows itself (an easy way to do this is to pass the splash shape to the main form in your constructor):
static void Main() { Application.SetCompatibleTextRenderingDefault(false); SplashForm splash = new SplashForm(); splash.Show(); splash.Refresh(); // make sure the splash draws itself properly Application.EnableVisualStyles(); Application.Run(new MainForm(splash)); } public partial class MainForm : Form { SplashForm _splash; public MainForm(SplashForm splash) { _splash = splash; InitializeComponent(); } protected override void OnLoad(EventArgs e) { base.OnLoad(e); // or do all expensive loading here (or in the constructor if you prefer) _splash.Close(); } }
Alternative: If you prefer not to pass the burst to MainForm (perhaps this seems inelegant), then subscribe to the MainForm Load event and close the splash screen there:
static class Program { static SplashForm _splash; [STAThread] static void Main() { Application.SetCompatibleTextRenderingDefault(false); _splash = new SplashForm(); _splash.Show(); _splash.Refresh(); Application.EnableVisualStyles(); MainForm mainForm = new MainForm(); mainForm.Load += new EventHandler(mainForm_Load); Application.Run(mainForm); } static void mainForm_Load(object sender, EventArgs e) { _splash.Dispose(); } }
As mentioned in this thread , a potential drawback of this solution is that the user will not be able to interact with the screensaver. However, this is usually not required.
Igby Largeman
source share