VB程序中的处理器使用情况 [英] Processor usage in VB program

查看:96
本文介绍了VB程序中的处理器使用情况的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个VB.Net 1.1应用程序,它必须通过

TCP / IP来收听消息。


当一个到达它排队,然后在一个单独的线程处理,而

主线程回去听更多。


当我看到任务管理器时,它表明该程序占用处理器的100%

,除非另一个应用程序需要运行。这是正常的吗?请

我需要担心吗?如果有的话有没有办法修改主要的听力任务

这样它就没有使用这么多的资源呢?


我还是挺的VB.Net的新手,所以请尽量保持简单!


谢谢

I''m writing a VB.Net 1.1 app that has to listen for messages coming to it via
TCP/IP.

When one arrives it it queued and then processed on a seperate thread while
the main thread goes back to listening for more.

When I look at the Task Manager, it shows that the program is taking up 100%
of the processor unless another application needs to run. Is this normal? Do
I need to worry? If so is there any way of modifying the main listening task
so that it is not using so much of the resources?

I''m still quite new to VB.Net so please try to keep things simple!

Thanks

推荐答案

<循环中的
,尝试在某处插入System.Threading.Thread.Sleep(sleepTimeInMs)

(通常在循环结束之前)...它可能会

帮助...


我希望它有所帮助


ThunderMusic


John S < JS *** @ newsgroup.nospam>在消息中写道

news:86 ********************************** @ microsof t.com ...
Hi,
in your loops, try to insert a System.Threading.Thread.Sleep(sleepTimeInMs)
somewhere (usually just before the end of the loop)... it will probably
help...

I hope it helps

ThunderMusic

"John S" <js***@newsgroup.nospam> wrote in message
news:86**********************************@microsof t.com...
我正在编写一个VB.Net 1.1应用程序,它必须通过TCP / IP侦听来自它的消息。
>
当一个人到达时,它会排队,然后在单独的线程上进行处理
主线程会回去听更多。

当我看到任务管理器,它表明该程序占用了处理器的100%,除非另一个应用程序需要运行。这是正常的吗?
我需要担心吗?如果是这样,有什么方法可以修改主要的听力任务
这样它就不会使用这么多的资源了吗?

我对VB来说还是一个新手。因此请尽量保持简单!

谢谢
I''m writing a VB.Net 1.1 app that has to listen for messages coming to it
via
TCP/IP.

When one arrives it it queued and then processed on a seperate thread
while
the main thread goes back to listening for more.

When I look at the Task Manager, it shows that the program is taking up
100%
of the processor unless another application needs to run. Is this normal?
Do
I need to worry? If so is there any way of modifying the main listening
task
so that it is not using so much of the resources?

I''m still quite new to VB.Net so please try to keep things simple!

Thanks



>当一个人到达它时,它会排队,然后在一个单独的线程上进行处理,而
> When one arrives it it queued and then processed on a seperate thread while
主线程会回到监听更多。

当我查看任务管理器时,它显示该程序占用处理器的100%,除非另一个应用程序需要运行。这是正常的吗?
the main thread goes back to listening for more.

When I look at the Task Manager, it shows that the program is taking up 100%
of the processor unless another application needs to run. Is this normal?




不,不正常。一个线程或另一个线程消耗cpu周期,你需要修复它。
需要修复它。我建议你不要启动工作线程 - 让主要的

线程继续排队并让队列增长。如果你仍然盯着

100%,那么罪魁祸首就是主线,如果没有,罪魁祸首是工人

线程。

在任何情况下,问自己的问题是:当什么都没有时,

开启,线程在做什么?应该用
阻止所有线程,这样系统空闲进程几乎100%挂钩。应该阻止主线程

监听传入数据。工作线程应该在主要的

线程的控制下运行或阻止。



No, not normal. One thread or the other is consuming cpu cycles, and you
need to fix that. I suggest you not start the worker thread - let the main
thread keep enqueuing and let the queue grow. If you are still pegged at
100%, then the culprit is the main thread, if not, the culprit is the worker
thread.

In any case, the question to ask yourself is this: when nothing is going
on, what are the threads doing? All threads should be blocked by something
so that the system idle process is pegged at nearly 100%. The main thread
should be blocked listening for incoming data. The worker thread should
either be not running or blocked on something under the control of the main
thread.


John S< js *** @ newsgroup.nospam>写道:
John S <js***@newsgroup.nospam> wrote:
我正在写一个VB.Net 1.1应用程序,它必须通过TCP / IP侦听来自它的消息。

当一个人到达时它排队,然后在一个单独的线程上进行处理,而主线程又回到了监听更多。

当我查看任务管理器时,它显示该程序占用了100个处理器的%
除非另一个应用程序需要运行。这是正常的吗?我需要担心吗?如果是这样有什么方法可以修改主要的听力任务
以便它没有使用这么多的资源?

我对VB.Net还是很新的所以请试试保持简单!
I''m writing a VB.Net 1.1 app that has to listen for messages coming to it via
TCP/IP.

When one arrives it it queued and then processed on a seperate thread while
the main thread goes back to listening for more.

When I look at the Task Manager, it shows that the program is taking up 100%
of the processor unless another application needs to run. Is this normal? Do
I need to worry? If so is there any way of modifying the main listening task
so that it is not using so much of the resources?

I''m still quite new to VB.Net so please try to keep things simple!




不,这不正常。


你能发一个简短但完整的程序这表明

问题?


http://www.pobox.com/~skeet/csharp/complete.html 了解详情

我的意思是什么。


-

Jon Skeet - < sk *** @ pobox.com>
http://www.pobox.com/~skeet 博客: http://www.msmvps.com/jon.skeet

如果回复该群组,请执行不要给我发邮件



No, that''s not normal.

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too


这篇关于VB程序中的处理器使用情况的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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