我在下面的代码中花费了很多时间。我在想有4个线程将从文件中读取ID,然后转储由ConnectToServiceAndDump完成的详细信息。由于所有ID都是唯一的,所以我可以4个线程接4个线程唯一ID,并调用ConnectToServiceAndDump。我已经尝试了Threading类将线程数设置为4,但是如果我将它保留在while循环中是行不通的。或类似这样的方法://- create a list.. which contains all the ids//- create a new thread //- in a theard safe way pop a loan from list //- dump this id by calling service in the same thread //- use ConcurrentQueue(T) and Enqueueusing (StreamReader sr = new StreamReader($@"{File}")){ var ids = sr.ReadLine(); while (ids != null) { ConnectToServiceAndDump(client, ids, outputSubdirectoryName); ids = sr.ReadLine(); }}
1 回答
- 1 回答
- 0 关注
- 285 浏览
添加回答
举报
0/150
提交
取消