学无先后,达者为师

网站首页 编程语言 正文

C# 压榨cpu的办法(推荐)_C#教程

作者:飞起来的帅哥   更新时间: 2022-03-19 编程语言

修改num的值,观察cpu的核数,例如我电脑是8核的,改成8,运行时各个核都能跑满。

static void Main(string[] args)
        {
            int num = 8;
            Task[] tasks = new Task[num];
            for (int i = 0; i < num; i++)
            {               
                tasks[i] = Task.Run(() => {
                    while (true)
                    {
                        Console.WriteLine("aaa");
                    }
                });
            }
            Task.WaitAll(tasks);
        }

原文链接:https://www.cnblogs.com/feiqilai/p/15740351.html

栏目分类
最近更新