.NET Framework Class Library
WaitHandle..::.WaitOne Method

Updated: July 2008

Blocks the current thread until the current WaitHandle receives a signal.

Overload List

  NameDescription
Public methodSupported by the .NET Compact FrameworkSupported by the XNA FrameworkWaitOne()()()Blocks the current thread until the current WaitHandle receives a signal.
Public methodWaitOne(Int32)Blocks the current thread until the current WaitHandle receives a signal, using a 32-bit signed integer to measure the time interval.
Public methodWaitOne(TimeSpan)Blocks the current thread until the current instance receives a signal, using a TimeSpan to measure the time interval.
Public methodSupported by the .NET Compact FrameworkSupported by the XNA FrameworkWaitOne(Int32, Boolean)Blocks the current thread until the current WaitHandle receives a signal, using a 32-bit signed integer to measure the time interval and specifying whether to exit the synchronization domain before the wait.
Public methodWaitOne(TimeSpan, Boolean)Blocks the current thread until the current instance receives a signal, using a TimeSpan to measure the time interval and specifying whether to exit the synchronization domain before the wait.
Top
See Also

Reference

Change History

Date

History

Reason

July 2008

Added new overloads: WaitOne(Int32) and WaitOne(TimeSpan).

SP1 feature change.

Tags :


Community Content

Remi Thomas
WaitOne can wait less than expected
When using WaitOne with a timeout (Int32 or TimeSpan), the method can exit before the expected time.

The smallest time element is a tick. A tick is not always a second multiple. Internally WaitOne convert the timeout in tick and round it under.

On very fast machine you can exit before expected time (some micro second before + very fast machine = expected time is not correct).

Tags : contentbug

Min-Yu Yang
RE: WaitOne can wait less than expected??
Remi, the paramter for WaitOne(Int32) is clearly documented as milliseconds. I wonder if you have any evidence that it's tick count instead?

Here is WaitOne(Int32)'s documented signature in C#:

public virtual bool WaitOne(
int millisecondsTimeout
)
Tags :

Dataflex
Milliseconds / ticks

Remi Thomas has not indicated that the parameter to WaitOne() is a tick count. He/she has indicated that the time parameter (in milliseconds) is converted to ticks, which is correct. Even if this conversion is exact, the real elapsed time is not exact (for several reasons). In the case addressed here, the suggested inaccuracy arises from rounding the tick count to an integer (and it is suggested that this rounding may be downward).

It is not clear from what is presented that this is a greater problem on a "fast" machine. Such machines are likely to have faster "ticks" and so timing is likely to be more accurate. Generally, it is advisable to round up a "tick" count to avoid a delay less than required (because of rounding down in conversion from milliseconds and because a wait for N ticks may always give a delay less than N tick times, because the first 'tick' always occurs less than one tick period after the call.

So, the "milliseconds" parameter should be increased at least one tick beyond the minimum tolerable delay. Since the tick time may vary from one machine to another, the simplest solution is usually to increase the parameter by some time which exceeds the tick time on all likely machines. Usually, it is possible to choose such a time increase which does not spoil the application.

Remember also that WaitOne() is not intended to provide accurate timing. The actual delay achieved will often be much greater, due to other activity in the machine.

Tags :

Page view tracker