[C #] performs asynchronous operations in the GUI

Source: Internet
Author: User

Performing asynchronous operations in the GUI

Order

Directory

I. Performing an asynchronous operation in a GUI program

The following actions are shown through the form sample-After clicking the button: ① changes the contents of the label to: "Doing" and disables the button (for execution), ② thread hangs for 3 seconds (simulates time-consuming operation), ③ changes the label content to: "Complete" and the button is enabled (indicates execution completion);

1      Public Partial classForm1:form2     {3          PublicForm1 ()4         {5 InitializeComponent ();6         }7 8         Private voidBtndo_click (Objectsender, EventArgs e)9         {Tenbtndo.enabled =false; OneLbltext.text =@"Doing"; A  -Thread.Sleep ( the); -  thebtndo.enabled =true; -Lbltext.text =@" Complete"; -         } -}

But the result of the execution is:

Figure 1-1

Problem found: It doesn't seem to be "Doing", and when dragged to the window, it's stuck, and after 3 seconds it suddenly changes to where you want to drag, and the text becomes "complete"?

The Analysis GUI program requires all display changes in the design to be done in the main GUI thread, such as click events and Mobile forms. Windows programs are implemented through messages, and messages are placed in message-pump-managed message queues.

Figure 1-2 Click events

Figure 1-3 Click event Specific execution process

"Original Address" http://www.cnblogs.com/liqingwen/p/5877042.html

[C #] performs asynchronous operations in the GUI

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.