Home > Software engineering >  A thread can affect the timer
A thread can affect the timer

Time:10-06

I use the timer is used to display the current time, and then establish a thread also shows the time, after running the program, the timer display time is normal, however, press the button to establish threads, refresh timer time slowly, sometimes three or four seconds to change once, is this why ah,

CodePudding user response:

no one

CodePudding user response:

Timer message priority level is very low, the accuracy is not high, is suitable for the situation of accuracy is not high, the condition of high precision recommended threads

CodePudding user response:

WM_TIMER low priority, if your program in ordinary do drawing or produce a lot of other priority is higher than its message, then its processing becomes slowly, and then, a timer itself is affected by the CPU is large, if the CPU load is very high, WM_TIMER the time difference will not, if you used to do simulation clock, then I suggest you SetTimer timeout setting a shorter, then inside WM_TIMER processing function as the basis of the refresh with real time difference:

Such as the SetTimer timeout is set to 100 ms, every OnTimer back off when judging whether the current time and the last time difference & gt; 1000 ms, and then decide whether to refresh:

 VOID GetLocalTime (LPSYSTEMTIME LPSYSTEMTIME//the system time); 

CodePudding user response:

The Timer is low priority

CodePudding user response:

Thread in the appropriate Sleep,
WM_TIMER as long as there is a message in the message queue will not be distributed, so the thread sends a message to a message queue can affect the timer

CodePudding user response:

The WM_TIMER message is a low priority message. The GetMessage and PeekMessage functions provides post this message only when no other who - priority messages are in The thread 's message queue.

CodePudding user response:

Also will cause the message thread thread takes up too much CPU card, update slow is normal.
Or you POST to the UI thread in the thread of messages very much (may be SET_WINDOWTEXT messages sent you thread, set the text information), low priority WM_TIMER message is not so easy to get a response.

CodePudding user response:

Above all, will,
  • Related