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 ;
}
}