Please have a look at the following code:
var splashForm = new SplashForm();
m_Thread = new Thread( () => System.Windows.Forms.Application.Run( splashForm ) )
m_Thread.Start();
// Do some initialization
// ...
// the following method just invokes `Close()` on the right thread
splashForm.Shutdown();
// Loop until the thread is no longer alive
// ...
System.Windows.Forms.Application.Run( mainForm );
It looks as if all works fine: first I see the splashscreen, later the mainform gets started. But somehow I get strange errors, like: graphical elements (a endless ProgressBar) are not showing up correctly.
EDIT: I have two progressbars, one on the splashscreen, on on the mainform. They both show the same (wrong) behaviour in endlessmode: no progress, just the pure background./EDIT
In my opinion this is due to the call of Application.Run()
on different threads. This errors can be eliminated by calling any function/property of the mainForm before starting the splashscreen - like, for instance
mainForm.Text = mainForm.Text;
Can anyone please confirm that this code can cause problems - or that it should behave alright and I have to look for the error somewhere else?
I already looked for splashscreen implementations and I know that it can be done differently. But I am interested in understanding this implementation and its possible problems. Thanks!