0

I have a problem, I added a splash screen. The splash screen appears. But it does not disappear after it's done and the main form has loaded.

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

    Thread thread = new Thread(new ThreadStart(showSplashScreen));
    thread.IsBackground = true;
    thread.Start();
    Thread.Sleep(1000);
    Main main = new Main();
    Application.Run(main);
    thread.Abort();
}

private static void showSplashScreen()
{
    Application.Run(new SplashForm());
}
zx485
  • 28,498
  • 28
  • 50
  • 59
  • 2
    Where's the code that is supposed to make the splash screen disappear? – jmcilhinney Mar 02 '18 at 00:02
  • Isn't the thread job to close it after abort? –  Mar 02 '18 at 00:02
  • Why are you even using two threads anyway? – jmcilhinney Mar 02 '18 at 00:02
  • This is what i found tutorials online for :/ –  Mar 02 '18 at 00:03
  • You need to use form `Close()` method, im not sure if aborting thread would close the form.. – Markiian Benovskyi Mar 02 '18 at 00:05
  • That code is dodgy for multiple reasons. For one thing, that `Abort` call won't be executed until you close the main form. – jmcilhinney Mar 02 '18 at 00:06
  • Oh okay, how can i make the code better :/? –  Mar 02 '18 at 00:07
  • The point of a splash screen is generally to display something while the main form is being created. That's why you need two threads. If you're going to sleep the UI thread anyway then there's no point using a second thread. Just display the splash screen on the UI thread, close it after one second using a `Timer` and then display the main form. – jmcilhinney Mar 02 '18 at 00:09
  • Well the main form is a bit slow, thats why i want to use a splash screen. –  Mar 02 '18 at 00:11
  • 1
    [Show Splash Screen during Loading the Main Form](https://stackoverflow.com/questions/32418695/show-splash-screen-during-loading-the-main-form) – Reza Aghaei Mar 02 '18 at 08:43

0 Answers0