For invoking the SplashForm use the MethodInvoker delegate (nothing but a built in delegate). While closing the SplashForm you got to use the InvokeRequired flag because it helps in avoiding the cross thread access issue on the SpashForm. Please modify your code to.
public Form1()
{
InitializeComponent();
//Do the splash
DoSplash();
Thread.Sleep(5000);
//Close the splash
CloseSplash();
Application.DoEvents();
}
private void DoSplash()
{
if (_splashForm != null)
return;
//Built in delegate
MethodInvoker methodInvoker = new MethodInvoker(ShowSplashScreen);
methodInvoker.BeginInvoke(null, null);//Invokes asynchronously
}
public void ShowSplashScreen()
{
_splashForm = new SplashForm();
Application.Run(_splashForm);
}
private void CloseSplash()
{
if (_splashForm == null)
return;
//Use this flag in order to avoid the cross thread access of _splashform
if (_splashForm.InvokeRequired)
{
//Built in delegate
MethodInvoker closeMethodInvoker = new MethodInvoker(CloseSplash);
_splashForm.Invoke(closeMethodInvoker);
}
else
{
_splashForm.Close();
_splashForm = null;
}
}
Tested both in Release and Debug mode and couldn't find any glitches.