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.
new AutoResetEvent(false).WaitOne(Period);
这段代码的目的是什么?为什么不使用 Thread.Sleep 呢?
是的,那个代码很愚蠢。由于AutoResetEvent在new这一行中,没有其他任何东西引用相同的AutoResetEvent,所以没有任何东西会发出信号。ASleep会更简单。
AutoResetEvent
new
Sleep
如果使用得当,使用 anAutoResetEvent可以让您等待其他东西“打开大门”(假设它尚未打开)或超时。另请注意,每次WaitOne成功时门都会自动关闭。
WaitOne
但是,此代码没有正确使用它,并且不允许这样做。