通知等待队列中的线程锁定对象状态的更改。Notifies a thread in the waiting queue of a change in the locked object's state.
public: static void Pulse(System::Object ^ obj);
public static void Pulse (object obj);
static member Pulse : obj -> unit
Public Shared Sub Pulse (obj As Object)
线程正在等待的对象。The object a thread is waiting for.
obj parameter is
调用线程不拥有指定对象的锁。The calling thread does not own the lock for the specified object.
Pulse发送正在等待的对象。Only the current owner of the lock can signal a waiting object using
当前拥有指定对象的锁的线程调用此方法，以向第一个线程发出锁。The thread that currently owns the lock on the specified object invokes this method to signal the next thread in line for the lock. 接收到脉冲后，等待线程会移动到就绪队列。Upon receiving the pulse, the waiting thread is moved to the ready queue. 如果调用
Pulse的线程释放锁定，则就绪队列中的下一个线程（不一定是 pulsed 的线程）将获取该锁。When the thread that invoked
Pulse releases the lock, the next thread in the ready queue (which is not necessarily the thread that was pulsed) acquires the lock.
类不维护指示已调用方法的Pulse状态。 MonitorThe Monitor class does not maintain state indicating that the Pulse method has been called. 因此，如果在没有Pulse线程等待的情况下调用，则下一个调用Wait块的线程Pulse就好像从未调用过。Thus, if you call Pulse when no threads are waiting, the next thread that calls Wait blocks as if Pulse had never been called. 如果两个线程正在Pulse使用Wait并进行交互，这可能会导致死锁。If two threads are using Pulse and Wait to interact, this could result in a deadlock. 这与AutoResetEvent类的行为相比较：如果通过调用其AutoResetEvent Set方法向发出信号，并且没有等待的线程，则在AutoResetEvent线程调用WaitOne、 WaitAny或WaitAll之前，将一直保持终止状态。Contrast this with the behavior of the AutoResetEvent class: If you signal an AutoResetEvent by calling its Set method, and there are no threads waiting, the AutoResetEvent remains in a signaled state until a thread calls WaitOne, WaitAny, or WaitAll. 线程并返回到信号状态的版本。AutoResetEventThe AutoResetEvent releases that thread and returns to the unsignaled state.
请注意，同步对象包含多个引用，包括对当前持有锁的线程的引用、对就绪队列的引用（其中包含准备好获取锁的线程）以及对等待队列的引用（包含等待对象状态更改通知的线程。Note that a synchronized object holds several references, including a reference to the thread that currently holds the lock, a reference to the ready queue, which contains the threads that are ready to obtain the lock, and a reference to the waiting queue, which contains the threads that are waiting for notification of a change in the object's state.