Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

SetTimer() Should Not Be Used in Console Applications

28 views
Skip to first unread message

Cen

unread,
Oct 29, 2009, 4:14:11 AM10/29/09
to
���ڵ�SDK�ĵ�, ò��û��ô����ý���, http://support.microsoft.com/kb/û��.

SetTimer() Should Not Be Used in Console Applications

PSS ID Number: Q102482

Authored 03-Aug-1993 Last modified 19-May-1995

The information in this article applies to:

- Microsoft Win32 Software Development Kit (SDK) versions 3.1, 3.5,
3.51, and 4.0


SUMMARY


SetTimer() was not designed to be used with a console application because
it requires a message loop to dispatch the timer signal to the timer
procedure. In a console application, this behavior can be easily emulated
with a thread that is set to wait on an event.


MORE INFORMATION


In Windows NT 3.1, SetTimer() can work within a console application, but it
requires a thread in a loop calling GetMessage() and DispatchMessage().

For example,

while (1)
{
GetMessage();
DispatchMessage();
}

Because this requires a thread looping, there is no real advantage to
adding a timer to a console application over using a thread waiting on an
event.

Another option is to use a multimedia timer, which does not require a
message loop and has a higher resolution. In Windows NT 3.5, the resolution
can be set to 1 msec using timeBeginPeriod(). See the help for
timeSetEvent() and the Multimedia overview. Any application using
Multimedia calls must include MMSYSTEM.H, and must link with WINMM.LIB.

Additional reference words: 3.10 3.50 3.51 4.00 95
KBCategory: kbprg
KBSubcategory: UsrMisc

acc

unread,
Oct 29, 2009, 4:42:05 AM10/29/09
to
settimer ���Ǹ��ص�����Ҳ��ͨ�� dispatchmessage ���õİɣ��ǵ� programming
windows ������ý�嶨ʱ����ʵ������һ���̡߳�

"Cen" <C...@rixi.an> д����Ϣ����:hcbisq$ouq$1...@news.eternal-september.org...


Cen

unread,
Oct 29, 2009, 8:34:38 AM10/29/09
to
锟斤拷锟较达拷锟斤拷DispatchMessage锟斤拷源锟诫看锟斤拷锟斤拷锟斤拷SetTimer锟斤拷ProcTimer.
timeSetEvent锟皆达拷锟竭筹拷, 锟斤拷锟斤拷1ms锟斤拷SetTimer锟斤拷10ms锟斤拷, 锟斤拷10ms锟斤拷锟铰碉拷timeSetEvent锟斤拷锟皆憋拷证锟斤拷锟斤拷, 偶锟斤拷锟筋几锟斤拷(锟斤拷锟叫讹拷影锟斤拷, Windows锟斤拷锟斤拷实时系统).


ntoskrnl.exe!KiSwapContext+0x2e
ntoskrnl.exe!KiSwapThread+0x46
ntoskrnl.exe!KeWaitForSingleObject+0x1c2
ntoskrnl.exe!KiSuspendThread+0x18
ntoskrnl.exe!KiDeliverApc+0x124
ntoskrnl.exe!KiSwapThread+0x64
ntoskrnl.exe!KeWaitForMultipleObjects+0x284
ntoskrnl.exe!NtWaitForMultipleObjects+0x2a2
ntoskrnl.exe!KiFastCallEntry+0xf8
ntdll.dll!KiFastSystemCallRet
ntdll.dll!NtWaitForMultipleObjects+0xc
WINMM.dll!timeThread+0x3a
kernel32.dll!BaseThreadStart+0x37

"acc" <jo...@sina.com> wrote:
> settimer 锟斤拷锟角革拷锟截碉拷锟斤拷锟斤拷也锟斤拷通锟斤拷 dispatchmessage 锟斤拷锟矫的吧o拷锟角碉拷 programming windows 锟斤拷锟斤拷锟斤拷媒锟藉定时锟斤拷锟斤拷实锟斤拷锟斤拷锟斤拷一锟斤拷锟竭程★拷

�IJ���

unread,
Nov 6, 2009, 12:33:47 AM11/6/09
to
settimer��Ҫ����Ϣ���?��console�½���һ���µ��߳���ʵ�־Ϳ�����

"Cen" <C...@rixi.an> д����Ϣ news:hcbisq$ouq$1...@news.eternal-september.org...

0 new messages