我有一个线程正在调用两个单独的线程来做一些工作。每当任何工作完成时,都会调用 Waithandle.Set(0 并且在父工作线程结束时,我想 WaitAll 让两者都完成,然后再继续。但是 priceA() 仍然首先出现,然后是 PriceB ()。
new Thread(() =>
{
new Thread(() =>
{
PriceA = _service.GetPriceA();
_waithandle[0].Set();
}).Start();
new Thread(() =>
{
PriceB = _service.GetPriceB();
_waithandle[1].Set();
}).Start();
WaitHandle.WaitAll(_waithandle);
}).Start();
Console.WriteLine("Hello");
我错过了什么?
更新:
private EventWaitHandle[] _waithandle;
托儿:
_waithandle[0] = new ManualResetEvent(false);
_waithandle[1] = new ManualResetEvent(false);