您应该通过ManualResetEvent执行此操作。
ManualResetEvent mre = new ManualResetEvent();
mre.WaitOne(); // This will wait
在另一个线程上,显然您需要参考 mre
mre.Set(); // Tells the other thread to go again
一个完整的例子,它将打印一些文本,等待另一个线程做某事然后恢复:
class Program
{
private static ManualResetEvent mre = new ManualResetEvent(false);
static void Main(string[] args)
{
Thread t = new Thread(new ThreadStart(SleepAndSet));
t.Start();
Console.WriteLine("Waiting");
mre.WaitOne();
Console.WriteLine("Resuming");
}
public static void SleepAndSet()
{
Thread.Sleep(2000);
mre.Set();
}
}