Introduction to Splash Screen

Started by thiruvasagamani, May 21, 2009, 03:55 PM

Previous topic - Next topic

thiruvasagamani

Introduction

This example demonstrates how to create a splash screen that is run on a thread separate from the main thread. This is done so as to allow the main thread to process loading and initialization while not having to explicitly update a progress animation. It is also advantageous to have the splash form on a separate thread so that it can process its own messages and thus receive paint messages when other applications interfere with its drawing. The main form will not be receiving these messages as it is theoretically busy in a load function and not processing messages.

The splash screen consists of a static background and an 8 cell animation that moves from left to right across the bottom of the image at a frame rate dependant, hard-coded rate. The animation was designed in this fashion to keep the code simple but still allow it to demonstrate how to optimize a draw routine by only updating areas of the background that were invalidated in the previous animation draw cycle. This optimization also helps identify the need for receiving paint messages while running on a separate thread because other applications may invalidate the form requiring it to redraw the entire background. On a single thread, these paint messages would not be received by the splash screen form until the main form had completed its processing – unless the code was peppered with Application.DoEvents() calls which is not an ideal or consistent solution.

The busy animation is updated at regular periodic intervals by a threaded timer (yes another thread). This allows it to give the processor back to the main form while it waits for its next draw cycle. Timing of the splash screen's total duration is also tracked using this timer.

The sample source code demonstrates the following concepts:

    * Loading and displaying a static background image
    * Loading and displaying an animated image
    * Starting two forms on separate threads
    * Invoking an EventHandler to shutdown a form on a separate thread
    * Creating a threaded timer
    * Loading embedded resources
    * Optimizing drawing by tracking invalid (dirty) rectangles

All of the splash screen interfaces are implemented in the form SplashForm so as to keep the interaction with the main form, appropriately title, MainForm as clean as possible. The code for this sample is available in Visual Basic and C# but in the interest of concision, this document refers only to the C# sample code.
Thiruvasakamani Karnan


dhoni

this information gives me more useful to know about splash screen