有没有办法在 C# 中唤醒休眠线程?那么,让它休眠很长时间,然后在您需要处理工作时唤醒它?
最佳答案
安AutoResetEvent
对象(或另一个 WaitHandle
实现)可用于休眠,直到收到来自另一个线程的信号:
// launch a calculation thread
var waitHandle = new AutoResetEvent(false);
int result;
var calculationThread = new Thread(
delegate
{
// this code will run on the calculation thread
result = FactorSomeLargeNumber();
waitHandle.Set();
});
calculationThread.Start();
// now that the other thread is launched, we can do something else.
DoOtherStuff();
// we've run out of other stuff to do, so sleep until calculation thread finishes
waitHandle.WaitOne();
关于c# - 有没有办法唤醒 sleep 线程?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3460280/