这种类型的实现是否存在问题,在继续之前等待一批线程完成,具体情况如下:
public List[Customer] ProcessCustomersPrices(List [Customer] Customers) { [Code to check Customers and deep copy Cust data into newCustomers] List[Thread] ThreadList = new List[Thread](); foreach(Customer cust in Customers) { ThreadList.Add(new Thread(() => CloneCustomerPrices(cust.Prices, newCustomer))); } Action runThreadBatch = () => { ThreadList.ForEach(t => t.Start()); ThreadList.All (t => t.Join([TimeOutNumber])); }; runThreadBatch(CopyPriceModelsCallback, null); [More Processing] return newCustomers; }
答案 0 :(得分:1)
对我来说很有意义,只要线程在超时结束时完成。不确定newCustomer是什么(与cust相同)。如果是这种情况,我也不知道如何计划只返回其中一个。
答案 1 :(得分:1)
等待实现似乎很好,只需确保CloneCustomerPrices是线程安全的。