Details of AsyncWaitHandle.WaitOne
1)The call AsyncWaitHandle.WaitOne开发者_如何学C may block client or will definitely block the client?.
2)What is the difference between WaitAll,WaitOne,WaitAny?
WaitHandle.WaitOne()
is an instance method that will block until the wait handle is signalled (when the operation is completed). If it has already been signalled previously (i.e. operation already completed) it is possible that the call toWaitOne()
will not block.WaitHandle.WaitAll()
andWaitHandle.WaitAny()
are static methods that allow you to specify a number of wait handles to monitor simultaneously:WaitHandle.WaitAll()
will wait until all of the specified handles have been signalled before it returns.WaitHandle.WaitAny()
will return as soon as any of the specified handles have been signalled.
These methods allow you to monitor a number of outstanding asynchronous operations at the same time.
Background: AsyncWaitHandle
is the name of a property on the IAsyncResult
interface. The actual type of this property is WaitHandle
, which is an abstract base class for types such as Semaphore
, Mutex
, and Manual/AutoResetEvent
.
See also: Blocking Application Execution Using an AsyncWaitHandle (MSDN)
The methods allow you to wait on a windows events. WaitOne is non-static and waits on the event handle for that object. WaitAll and WaitAny are static class-wide methods that wait an a group of event handlers. WaitAll waits for all events to signal and WaitAny for a single event in the group.
精彩评论