编写程序如下:
class Program
{
static void Main(string[] args)
{
Thread thread1 = new Thread(new ThreadStart(Fun1));
Thread thread2 = new Thread(new ThreadStart(Fun2));
thread1.Start();
Thread.Sleep(1000);
thread2.Start();
} static void Fun1()
{
int j = 0;
while (true)
{ for (int i = 0; i < 10000; i++)
{
j = j + i;
}
}
} static void Fun2()
{
int j = 0;
while (true)
{ for (int i = 0; i < 10000; i++)
{
j = j + i;
}
}
}
}
每次运行cpu使用率都是100%,怎么样能是cpu的使用率降下来呢?
class Program
{
static void Main(string[] args)
{
Thread thread1 = new Thread(new ThreadStart(Fun1));
Thread thread2 = new Thread(new ThreadStart(Fun2));
thread1.Start();
Thread.Sleep(1000);
thread2.Start();
} static void Fun1()
{
int j = 0;
while (true)
{ for (int i = 0; i < 10000; i++)
{
j = j + i;
}
}
} static void Fun2()
{
int j = 0;
while (true)
{ for (int i = 0; i < 10000; i++)
{
j = j + i;
}
}
}
}
每次运行cpu使用率都是100%,怎么样能是cpu的使用率降下来呢?
while (true)
{ for (int i = 0; i < 10000; i++)
{
j = j + i;
}
Thread.Sleep(100);
}
{
j = j + i;
加 Thread.Sleep(100); }