Microsoft KB Archive/102482

From BetaArchive Wiki
< Microsoft KB Archive
Revision as of 20:57, 16 July 2020 by X010 (talk | contribs) (1 revision imported: importing part 2)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

INFO: SetTimer() Should Not Be Used in Console Applications

Q102482



The information in this article applies to:


  • Microsoft Win32 Software Development Kit (SDK)





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 query words:

Keywords : kbOSWinNT kbOSWin2000 kbSDKWin32 kbGrpDSUser kbOSWin95 kbOSWin98 kbWndw kbWndwMsg
Issue type : kbinfo
Technology : kbWin32SDKSearch kbAudDeveloper kbSDKSearch kbWin32sSearch


Last Reviewed: July 12, 2000
© 2001 Microsoft Corporation. All rights reserved. Terms of Use.