"C #" Windows program message mechanism

Source: Internet
Author: User

First, the Windows program message mechanism


1. The Windows Program message mechanism is implemented using Message Queuing.

(1), the UI thread is the main thread that manages the entire form and the running of the child controls.

(2), all messages on a form are the primary source of Message Queuing.

(3), PeekMessage, getmessage are used to view application message queues, and messages are dispatched when messages are in the queue.

GetMessage is returned only if there is a message in the message queue, no message getmessage in the queue waits until the next message appears. During the waiting period, the application cannot execute any instructions. That is, when the queue is empty, the getmessage is blocked, causing the while loop to stop, preventing a program from draining the CPU.

Regardless of whether or not the application message queue has a message, the PeekMessage function returns immediately, allowing the program to continue executing the following statement (no message executes other instructions, the message is generally dispatched, and other instructions are executed).

2, ISynchronizeInvoke attribute invokerequired, is used to determine whether the Windows Forms thread and the current caller thread are the same. If so, access the GUI control directly; otherwise, use Invoke or BeginInvoke to access the UI control.

The control class invoke and BeginInvoke are implemented through the Windows Messaging Mechanism (PostMessage).

Second, reference materials:

(1),peekmessage&getmessage

Http://www.cnblogs.com/faceang/archive/2010/05/25/1743757.html

(2),peekmessage use method

Http://www.cnblogs.com/likebeta/archive/2012/03/28/2421580.html

(3),Invoke and BeginInvoke

Http://www.cnblogs.com/worldreason/archive/2008/06/09/1216127.html

"C #" Windows program message mechanism

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.