0

I am trying to implement a splash screen similar to that which solved the issue Splash Screen waiting until thread finishes.

In my case I do not need threads. I want a login prompt once the DefineAlternateFrm constructor completes. Without the login, it works fine: once the constructor in defineAlternateFrm is done, the form is shown.

Adding a login form, it behaves differently: the login form prompt appears before the constructor of defineAlternateFrm is done. Weird, since there are no threads so I was expecting the prompt once the call for instantiating defineAlternateFrm is done. Then if the login succeed, it will show defineAlternateFrm.

My Code:

static class Program
{
    [STAThread]
    static void Main(string[] args)
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        new MyApp().Run(args);
    }
}

class MyApp : WindowsFormsApplicationBase
{
    protected override void OnCreateSplashScreen()
    {
        this.SplashScreen = new SplashScreen();
    }
    protected override void OnCreateMainForm()
    {
        var defineAlternateFrm = new DefineAlternateFrm(); // some works done

        var login = new LoginFrm();
        login.ShowDialog(); 

        // Then create the main form, the splash screen will close automatically
        this.MainForm = defineAlternateFrm ;
    }        
}
Community
  • 1
  • 1
ehh
  • 3,412
  • 7
  • 43
  • 91
  • Using above code, the result would be: It shows splash screen first, then shows the login form then shows your main form. What do you expect? – Reza Aghaei Jan 05 '16 at 13:09
  • The order you mentioned is correct but after login ended, it takes a lot of time to show the main form. The stuff is done in the constructor so why it takes a lot of time to show the main form since the constructor was done before the login. Without the login, it behave fine, once the splash disappear, the Main form is shown immediately – ehh Jan 05 '16 at 13:12

0 Answers0