There is a current series of 13 WebCasts on Mobile development by Maarten Struys over at http://msdn.microsoft.com/mobility/webcast/ that are well worth checking out if you are working with WM5. In part 6 he shows a way of creating a splash screen on a separate thread, which is pretty neat. I have summarised the steps here, since I have not seen them on the web before, but I urge you to view the webcasts for more detail on this and many more topics.
Main Form
Create the following variables for your main form (you need to add System.Threading to your namespaces):
private Thread splashScreenThread;
private AutoResetEvent appInitialized;
In constructor for your main form add the following:
appInitialized =
new AutoResetEvent(false);
splashScreenThread = new Thread(SplashScreenThread);
splashScreenThread.Priority = ThreadPriority.AboveNormal;
splashScreenThread.Start();
Now create the SplashScreenThread function which actually displays your splash screen (called Splash in the code below). Note that the constructor has been modified to take two parameters (we'll see how to do this later on)
private void SplashScreenThread()
{
Splash splash = new Splash(appInitialized,5);
splash.ShowDialog();
}
After you have done any initialisation work in the Main form (perhaps in Form_load) you can tell the splash screen you are ready and then wait for it to finish with code like the following:
appInitialized.Set();
Thread.CurrentThread.Priority = ThreadPriority.AboveNormal;
splashScreenThread.Join();
Splash Screen
OK - over in the Splash form create the following variables:
private
AutoResetEvent mainAppInitialized;
private int minDisplayTime;
and change the constructor to takes those parameters:
public Splash(AutoResetEvent appInitialized,int minimumDisplayTime)
{
InitializeComponent();
mainAppInitialized = appInitialized;
minDisplayTime = minimumDisplayTime;
displayTimer = new System.Windows.Forms.Timer();
displayTimer.Interval = minimumDisplayTime * 1000;
displayTimer.Tick += new EventHandler(displayTimer_Tick);
displayTimer.Enabled = true;
}
You might want to do other work in the splash screen (as Maartyn does in the webcast) but here I am just trying to show the essential steps.
Finally add the tick event handler:
void
displayTimer_Tick(object sender, EventArgs e)
{
displayTimer.Enabled = false;
displayTimer.Tick += new EventHandler(displayTimer_Tick);
displayTimer.Dispose();
mainAppInitialized.WaitOne();
this.Close();
}
Your done. All that is needed now is to add a pretty graphic to the splash screen.
HTH
Ian