使用 C# 检测客户端有多少个核心
我正在创建一个程序,可以同时执行多个后台任务。我想根据客户端运行的核心数量创建多个线程来执行这些操作。这样如果他们使用多核处理器,程序会运行得更快。有没有办法让 C# 检查处理器有多少个核心?查找处理器的型号也可以。
I am creating a program that will multiple background tasks simultaneously. I would like to create a number of threads to do these based on the number of cores that a client is running. So that if they are using a multi-core processor, the program will run faster. Is there any way to have C# check how many cores a processor has? Finding model of the processor would also work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用Environment.ProcessorCount,尽管我会避免这种优化,因为任务并行库 会为您处理好这一切。
You could use
Environment.ProcessorCount
, although I would avoid this sort of optimization because the Task Parallel Library takes care of it for you.