Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试同步一个异步方法。异步版本的主要优点是它释放了线程池中的一个槽。我想在我的同步版本中保留这个优势。当我使用 AutoResetEvent.WaitOne() 时,它在线程池使用方面相当于 Thread.Sleep() 吗?
当您调用WaitOne当前线程时,将阻塞并等待事件发出信号。就像Thread.Sleep线程不会被释放到线程池一样。不同之处在于Thread.Sleep你需要指定一个固定的时间,在此期间当前线程将被阻塞,而WaitOne将阻塞直到其他一些线程调用Set或发生超时。
WaitOne
Thread.Sleep
Set