使用 C# 检测客户端有多少个核心

发布于 2024-10-10 23:10:27 字数 115 浏览 3 评论 0原文

我正在创建一个程序,可以同时执行多个后台任务。我想根据客户端运行的核心数量创建多个线程来执行这些操作。这样如果他们使用多核处理器,程序会运行得更快。有没有办法让 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技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蓝颜夕 2024-10-17 23:10:27

您可以使用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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文