Delayed operation in VC function

zhaozj2021-02-16  96

Speaking of the latency in the program, what do you think of doing, open a thread? If my program only uses a single thread, I want to return the function to the value, but can't handle other messages like using the SLEEP function?

I summed it here to summarize several delayed methods that can be seen in the forum. In addition, it is mainly to learn someone's Sources, copyright is not in me, if this article is useful, please thank these authors in the text (ID on 9CBS): laiyiling (most familiar stranger), Qunkangli (fog marks), Tyzyx (Frying Japan Island).

From a stranger's handling method, this is the maximum temperature span, at least in seconds: http://community.9cbs.net/expert/faq/faq_index.asp? Id = 195559 Seeing not only one People asked. In fact, it is estimated that the stranger is the code directly handwritten. It is not Copy from the block. There are some handles, everyone will adjust it, do #include

COleDateTime start_time = COleDateTime :: GetCurrentTime (); COleDateTimeSpan end_time = COleDateTime :: GetCurrentTime () - start_time; while (end_time.GetTotalSeconds () <= 2) {MSG msg; GetMessage (& msg, NULL, 0,0); TranslateMessage ( & msg); DispatchMessage (& msg); end_time = COleDateTime :: GetCurrentTime () - start_time;} notice that I put the original text of PreTranslateMessage (& msg); replacement for: TranslateMessage (& msg); DispatchMessage (& msg); the reason is that not only Use only in the MFC, and PretranslateMessage has limitations and may cause thread messages. There is also a point of illustration, because the member functions of the ColedateTimespan class include: getTotalminutes, GetTotalDays, the latency of a larger time period can be achieved.

To a smaller time span, perform millisecond delay with gettickcount to play: dword dwstart = gettickcount (); dword dwend = dwstart; do {msg msg; getMessage (& MSG, NULL, 0, 0); TranslateMessage (& MSG ); DispatchMessage (& MSG); dwend = gettickcount ();} while ((DWEND - DWSTART) <= 2000);

Then it is a microsecond delay: Large_integer Litmp; Longlong QPart1, QPart2; Double D = 0; QueryPerFormanceCounter (& Litmp); // Get initial value qPart1 = Litmp.quadpart; while (d <40) // What you want {QueryperFormanceCounter (& litmp); QPart2 = Litmp.quadpart; D = (Double) (qPart2 - qPart1);} Source: http://community.9cbs.net/expert/topicView1.asp? ID = 2663023. No changes, if you need a message in the delay in the microseconds, refer to the previous modification. Finally, if you can't satisfy, you will do the delay of the clock cycle:

#define nop_count 3 // Need yourself calculated according to NOP and LOOP's instruction cycle.

转载请注明原文地址:https://www.9cbs.com/read-14956.html

New Post(0)