namespace WindowsFormsApp1
{
public partial class 多线程减少CPU占用率 : Form
{
public 多线程减少CPU占用率()
{
InitializeComponent();
//线程1
Thread th1 = new Thread(thread1) { IsBackground = true };
//线程2
Thread th2 = new Thread(thread2) { IsBackground = true };
}
public void thread1()
{
while (true)
{
//...应用出代码
Thread.Sleep(1);//任务调度下,防止CPU占用过高
}
}
public void thread2()
{
while (true)
{
//...应用出代码
Thread.Sleep(1);
}
}
}
}
多线程减少CPU占用率
![](https://img-home.csdnimg.cn/images/20240711042549.png)