需要建议更好的解决方案,多线程,基于计时器的解决方案之间的选择......
问题描述:
我有一个设备在90毫秒后发送数据(基于Windows的解决方案),基于数据,经过一些操作后,我必须同时向tcp上的其他20个客户端发送数据。什么是更好的解决方案。可以基于计时器的解决方需要帮助。
我尝试过:
我试过多线程,但造成100%的CPU使用率,thread.sleep()函数也产生问题,bcoz有时tcp客户端也需要时间来响应。
I have a device that is sending data after 90 mili seconds(windows based solution) , on the basis of data, after some operations, I have to send data to 20 other clients on tcp Simultaneously. What can be the better solution. Can timer based solution work? Need help.
What I have tried:
I have tried multithreading, but causing 100 percent CPU usage, thread.sleep() Function is also creating problem, bcoz sometimes tcp clients also takes time to respond.
答
每90毫秒?这就是为什么你的CPU负载是100%。
查看.Net中的TPL内容
任务并行库(TPL)| Microsoft Docs [ ^ ]
Every 90 milliseconds? THAT is why your CPU load is 100%.
Check out the TPL stuff in .Net
Task Parallel Library (TPL) | Microsoft Docs[^]