The Flash form (C #) is displayed when the program starts #)

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.