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