We often do a lot of things in Form Loading events (for example, Loading Dictionary data), but we find that this time consumes a lot of time and it is impossible to predict the completion time, our first interface is locked until Loading is completed. to provide users with the best user experience, we should add a Flash Form. however, I have read many programmer programs and the Flash Form is still locked by the thread. In this article, I propose my implementation. I use:
Application. Idle event occurs when the Application completes processing and is about to enter Idle state.
The following is my reference implementation.
// Define the context of the program
Private static ApplicationContext context;
// Define the Flash form
Private static FlashForm flashForm;
/// <Summary>
/// Main entry point of the application.
/// </Summary>
[STAThread]
Static void Main ()
{
...
Context = new ApplicationContext ();
FlashForm = new FlashForm ();
// Bind an Idle event to handle Idle program events. Run the code segment after the flash form is displayed.
Application. Idle + = new EventHandler (Application_Idle );
FlashForm. Show ();
Application. Run (context );
}
Static void Application_Idle (object sender, EventArgs e)
{
// Clear the Idle event processing binding
Application. Idle-= new EventHandler (Application_Idle );
// Create the main form
Form1 form = new Form1 ();
Context. MainForm = form;
Application. DoEvents ();
// Display the main form
Context. MainForm. Show ();
Application. DoEvents ();
// Close the Flash form
FlashForm. Close ();
}
Now you have to beautify your Flash Form.