如何使用线程编辑列表

时间:2018-06-10 10:47:44

标签: c# multithreading list thread-safety

我有一个列表,想要添加一些项目。

我想要添加的项目必须花费一些时间来计算。 这就是为什么我想通过一个帖子来做。

这是我到目前为止所做的:

 private void ManageBWPCList(BWPC pInput)
 {      
     BWPCList.Add(pInput);
 }

 private void FillBWPC(String[] computers)
 {
    foreach(String computer in computers)
    {
        Thread thread = new Thread(() => ManageBWPCList(GetBWPC(computer)));
        thread.Start();
    }
 }

这适用于4个案例中的1个。

有时列表不会被填充或只能获得一半的项目。

非常感谢任何帮助。

0 个答案:

没有答案