如何修复障碍

时间:2019-07-08 05:51:59

标签: c# sockets

How to use await in a loop-在我的情况下,可能是单个列表项没有发送数据,在这里,我认为会发生相同的错误。

当我尝试从for中的客户端异步接收数据时,我遇到了问题,例如程序被阻塞,直到我从客户端获取数据为止。 我想在for中并行接收下一个客户端。客户端数量大于10000。客户端可能无法发送数据。 我希望有人能提供建议。谢谢

//Recieve
while (true)
{
   for (int i = 0; i < this.Clients[index].Count; i++)
   {
     var client = Clients[index][i];
     string str = await client.Recieve();
   }
}

//client.Recieve()
public StreamReader Stream { get; set; }

public Task<string> Recieve()
{
     return this.Stream.ReadLineAsync();
}

0 个答案:

没有答案
相关问题