100%CPU [英] 100% CPU

查看:103
本文介绍了100%CPU的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简单的VB.NET循环:


for i = 1 to 30000000

''做点什么

next


将我的计算机上的CPU驱动到100%利用率,以获得循环的

持续时间。 (几分钟)


如何修改此循环以让在同一个盒子上运行的其他(不相关的)
应用程序获得一些CPU时间?

TIA,


比尔

解决方案

12月28日星期日2003 19:44:38 -0800,bill salkin

< an ******* @ discussion.microsoft.com>写道:

简单的VB.NET循环:

对于i = 1到30000000
''做一些事情
下一步

驱动我的计算机上的CPU,以便在循环的持续时间内100%利用率。 (几分钟)

如何修改此循环以让在同一个盒子上运行的其他(无关)
应用程序获得一些CPU时间?

TIA,

比尔




添加:


System.Threading.Thread.Sleep(0)


为睡眠指定0将导致线程暂停,以便

其他等待线程可以执行。


// CHRIS


将一个Application.DoEvents()调用放入循环体中。


" ; bill salkin <一个******* @ discussions.microsoft.com>在消息中写道

news:04 **************************** @ phx.gbl ... < blockquote class =post_quotes>简单的VB.NET循环:

对于i = 1到30000000
''做一些事情
下一步

驱动器我的计算机上的CPU为循环持续时间的100%利用率。 (几分钟)

如何修改此循环以让在同一个盒子上运行的其他(无关)
应用程序获得一些CPU时间?

TIA,<比尔



On Sun,28 Dec 2003 19:44:38 -0800," ; bill salkin"

< an ******* @ discussion.microsoft.com>写道:

简单的VB.NET循环:

对于i = 1到30000000
''做一些事情
下一步

驱动我的计算机上的CPU,以便在循环的持续时间内100%利用率。 (几分钟)

如何修改此循环以让在同一个盒子上运行的其他(无关)
应用程序获得一些CPU时间?

TIA,<比尔




想我应该补充一点,如果你多次循环,

30百万,你也应该限制你打电话给睡觉的次数。

所涉及的开销肯定会加起来。


也许是这样的:


for i = 1 to 30000000

if i mod 5000 = 0 Then System.Threading.Thread.Sleep(0)

next i

// CHRIS


The simple VB.NET loop:

for i = 1 to 30000000
'' do something
next

drives the CPU on my computer to 100% utilization for the
duration of the loop. (Several minutes)

How can I modify this loop to let other (unrelated)
applications running on the same box get some CPU time?
TIA,

Bill

解决方案

On Sun, 28 Dec 2003 19:44:38 -0800, "bill salkin"
<an*******@discussions.microsoft.com> wrote:

The simple VB.NET loop:

for i = 1 to 30000000
'' do something
next

drives the CPU on my computer to 100% utilization for the
duration of the loop. (Several minutes)

How can I modify this loop to let other (unrelated)
applications running on the same box get some CPU time?
TIA,

Bill



Add this:

System.Threading.Thread.Sleep(0)

Specifying 0 for the sleep will cause the thread to suspend so that
other waiting threads can execute.

// CHRIS


Throw an Application.DoEvents() call into the body of the loop.

"bill salkin" <an*******@discussions.microsoft.com> wrote in message
news:04****************************@phx.gbl...

The simple VB.NET loop:

for i = 1 to 30000000
'' do something
next

drives the CPU on my computer to 100% utilization for the
duration of the loop. (Several minutes)

How can I modify this loop to let other (unrelated)
applications running on the same box get some CPU time?
TIA,

Bill



On Sun, 28 Dec 2003 19:44:38 -0800, "bill salkin"
<an*******@discussions.microsoft.com> wrote:

The simple VB.NET loop:

for i = 1 to 30000000
'' do something
next

drives the CPU on my computer to 100% utilization for the
duration of the loop. (Several minutes)

How can I modify this loop to let other (unrelated)
applications running on the same box get some CPU time?
TIA,

Bill



Thought I should add that if you''re doing a loop that many times,
30 million, you should also limit the number of times you call Sleep.
The overhead involved will definitely add up.

Maybe something like this:

for i = 1 to 30000000
if i mod 5000 = 0 Then System.Threading.Thread.Sleep(0)
next i
// CHRIS


这篇关于100%CPU的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆