为了账号安全,请及时绑定邮箱和手机立即绑定

在C#中使用线程或队列写入文件

在C#中使用线程或队列写入文件

C#
holdtom 2021-03-31 21:14:04
我在下面的代码中花费了很多时间。我在想有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 关注
  • 273 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信