Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / August 2005

Tip: Looking for answers? Try searching our database.

On the sleep()

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
hohhot - 02 Aug 2005 05:06 GMT
Hi, everyone,

I have a question on the sleep() function.

the prototype for sleep() is

VOID Sleep(
 DWORD dwMilliseconds
);

dwMilliseconds
[in] Minimum time interval for which execution is to be suspended, in
milliseconds.

But 1 milliseconds is too long for me, I need a short value for it, how can
I do?

Thanks a lot!
Peter van der Goes - 02 Aug 2005 13:49 GMT
> Hi, everyone,
>
[quoted text clipped - 15 lines]
>
> Thanks a lot!

I'm a bit confused. As one millisecond is 1/1000 of a second, what
circumstances would create a need to pause an application for < 1/1000 of a
second? Can you describe your situation so that alternative approaches might
be suggested?

Signature

Peter [MVP Visual Developer]
Jack of all trades, master of none.

hohhot - 03 Aug 2005 07:22 GMT
> > Hi, everyone,
> >
[quoted text clipped - 20 lines]
> second? Can you describe your situation so that alternative approaches might
> be suggested?

Thank you very much, Mr. Peter.

I will explain the situation more detail now:

We are developing a communication software on the PC side, the counterparter
is a MCU.

The sleep() is called for data synchronization,  but 1 millisecond is too
long -- the baud rate is 9600bps, so I need a solution, a more accurate
version sleep() for this purpose.
Dick Grier - 03 Aug 2005 16:13 GMT
Hi,

You cannot use Sleep for precise timing.  As Peter says, its minimum
resolution is 1 mS (but it may cause the thread to not execute for
considerably longer).  In fact, Windows is not a real-time OS, so any
accurate measurements are problematic.

You can use the QueryPerformanceCounter API calls for somewhat more precise
timing, but the actual precision (accuracy) will be less than the resolution
that it or any other method provides.

One thing that you must realize is that there is much more going on than the
things that you can control.  For example, in your application, the serial
port UART FIFO can buffer up to 16 bytes before an interrupt is generated
and processed -- so there may be that much latency involved in your
measurement.  However, it is possible for the serial data to be input by the
serial port driver BEFORE all 16 bytes have been buffered by the UART FIFO.
You will never know if this has or has not happened.

Also, Windows is a multitasking OS.  Since it isn't a real-time OS, any
other application (and lots of Windows own operations) will take an
indeterminate amount of time to execute.

Any measurements that you attempt that require precision better than the
basic 1 mS that most timing functions offer will be subject to hit-or-miss
operation.  That is, it may or may not work well enough.  IMO, any really
precise timing needs to be done in some purpose-built system.

Dick

Signature

Richard Grier  (Microsoft Visual Basic MVP)

See www.hardandsoftware.net for contact information.

Author of Visual Basic Programmer's Guide to Serial Communications, 4th
Edition ISBN 1-890422-28-2  (391 pages) published July 2004.  See
www.mabry.com/vbpgser4 to order.

hohhot - 04 Aug 2005 02:42 GMT
Thank you very much, Mr. Grier!

> Hi,
>
[quoted text clipped - 25 lines]
>
> Dick

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.