Relationship between Windows window message loops and multithreading

Source: Internet
Author: User

A process in Windows can contain multiple threads, consisting of multiple threads. in the Windows in an application, a form is called by a UI Threads ( User Interface Thread ) "is created by a special type of thread. A UI thread contains a message loop to a column. While the window is running, pressing the control or doing something to the window is equivalent to inserting the message into the message loop queue, and then the response function of the corresponding message is called by the system, causing the user operation to be responded to.

According to this work process, when the response function of a window message takes a lot of time, it must affect the window's response to the next message. Therefore, using multithreading should be a good choice for responding to more time-consuming operations. That is, a thread is created in the response function of the control, and the time-consuming operation is completed in the thread function.

WaitForSingleObject () is used to wait for a response to a thread function, which can also block the operation of the message loop queue and affect the window's response speed.


Note: Create thread functions: CreateThread (NULL, 0, ThreadProc, (LPVOID) NULL, 0, NULL);

Format of the thread function: DWORD WINAPI threadproc(LPVOID lpparameter);

among them, a thread function must be a global function or a static member function


Relationship between Windows window message loops and multithreading

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.