循环内存消耗? [英] Do loop memory consumption?

查看:75
本文介绍了循环内存消耗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的Timer循环消耗了我的开发PC的所有可用CPU时间。

我希望能够将CPU时间的使用限制在最小值,因为

it实际上并没有做任何事情,只是倒数剩下的时间。

非常感谢任何帮助。


比尔

昏暗t作为整数= 0


Dim Start,Finish,TotalTime As Double


''Start = Microsoft.VisualBasic.DateAndTime.Timer


完成=开始+ mSeconds''将结束时间设置为mseconds持续时间。



t + = 1

lblInfo.Text =" test timer - > " &安培; t $ / $

lblInfo.Refresh()


''等待5秒后再进行其他处理。


循环

The Timer loop below consumes all available CPU time from my development PC.
I would like to be able to restrict its use of CPU time to minimum since
it''s not actually doing anything but counting down the time left.
Any help is greatly appreciated.

Bill
Dim t As Integer = 0

Dim Start, Finish, TotalTime As Double

''Start = Microsoft.VisualBasic.DateAndTime.Timer

Finish = Start + mSeconds '' Set end time for mseconds duration.

Do While Microsoft.VisualBasic.DateAndTime.Timer < Finish

t += 1

lblInfo.Text = "test timer -> " & t

lblInfo.Refresh()

'' Do other processing while waiting for 5mseconds to elapse.

Loop

推荐答案



Bill Nguyen写道:

Bill Nguyen wrote:
下面的Timer循环从我的开发PC中消耗所有可用的CPU时间。
我希望能够将CPU时间的使用限制在最低限度,因为它实际上并没有做任何事情,只是减少了剩下的时间。非常感谢任何帮助。

比尔

Dim t As Integer = 0

Dim Start,Finish,TotalTime As Double

''Start = Microsoft.VisualBasic.DateAndTime.Timer

Finish = Start + mSeconds''将结束时间设置为mseconds持续时间。

同时Microsoft .VisualBasic.DateAndTime.Timer<完成

t + = 1

lblInfo.Text =" test timer - > " &安培; t

lblInfo.Refresh()

''等待5秒后再进行其他处理。

Loop
The Timer loop below consumes all available CPU time from my development PC.
I would like to be able to restrict its use of CPU time to minimum since
it''s not actually doing anything but counting down the time left.
Any help is greatly appreciated.

Bill
Dim t As Integer = 0

Dim Start, Finish, TotalTime As Double

''Start = Microsoft.VisualBasic.DateAndTime.Timer

Finish = Start + mSeconds '' Set end time for mseconds duration.

Do While Microsoft.VisualBasic.DateAndTime.Timer < Finish

t += 1

lblInfo.Text = "test timer -> " & t

lblInfo.Refresh()

'' Do other processing while waiting for 5mseconds to elapse.

Loop



修复此问题的一种方法是在你的lblInfo.Refresh()之后插入System.Thread.Sleep(100)




-

Tom Shelton [MVP]



One way to fix this would be to insert System.Thread.Sleep (100) right
after your lblInfo.Refresh ().

--
Tom Shelton [MVP]


比尔,


您是否考虑过使用System.Windows.Forms.Timer?

Mattias


-

Mattias Sj? gren [C#MVP] mattias @ mvps.org
http://www.msjogren .net / dotnet / | http://www.dotnetinterop.com

请回复到新闻组。
Bill,

Have you considered using System.Windows.Forms.Timer instead?
Mattias

--
Mattias Sj?gren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.


Tom;


这似乎解决了我的问题。我发出1000毫秒的CPU时间和b $ b b显着下降。使用的内存大概还差不多,但是我可以支付


另外一个问题,请:

我需要在用户中断循环按下STOP按钮。问题

btnStop(在同一表格上)在循环期间无法访问。

有没有办法在do循环期间检查按钮是否被按下

例程?


再次感谢;


Bill

Tom Shelton" < to*@mtogden.com>在消息中写道

news:11 ********************** @ j33g2000cwa.googlegr oups.com ...
Tom;

That seemed to solve my problem. I assinged 1000 miliseconds and CPU time
went down significantly. memory used still about the same, but that I can
afford!
Another question, please:
I need to interrupt the loop when user presses the STOP button. The problem
that btnStop(on the same form) is not accessible during the loop.
Is there a way to check if the button was pressed during the do loop
routine?

Thanks again;

Bill
"Tom Shelton" <to*@mtogden.com> wrote in message
news:11**********************@j33g2000cwa.googlegr oups.com...

Bill Nguyen写道:

Bill Nguyen wrote:
下面的Timer循环消耗了我开发的所有可用CPU时间
PC。
我希望能够限制它将CPU时间用于最小化,因为它实际上并没有做任何事情,只是倒数剩下的时间。
非常感谢任何帮助。

比尔

Dim t As Integer = 0

Dim Start,Finish,TotalTime As Double

''Start = Microsoft.VisualBasic.DateAndTime.Timer

Finish = Start + mSeconds''设置mseconds持续时间的结束时间。

同时Microsoft.VisualBasic.DateAndTime.Timer<完成

t + = 1

lblInfo.Text =" test timer - > " &安培; t

lblInfo.Refresh()

''等待5秒后再进行其他处理。

Loop
The Timer loop below consumes all available CPU time from my development
PC.
I would like to be able to restrict its use of CPU time to minimum since
it''s not actually doing anything but counting down the time left.
Any help is greatly appreciated.

Bill
Dim t As Integer = 0

Dim Start, Finish, TotalTime As Double

''Start = Microsoft.VisualBasic.DateAndTime.Timer

Finish = Start + mSeconds '' Set end time for mseconds duration.

Do While Microsoft.VisualBasic.DateAndTime.Timer < Finish

t += 1

lblInfo.Text = "test timer -> " & t

lblInfo.Refresh()

'' Do other processing while waiting for 5mseconds to elapse.

Loop


解决这个问题的一种方法是在你的lblInfo.Refresh()之后插入System.Thread.Sleep(100)


-
Tom谢尔顿[MVP]



One way to fix this would be to insert System.Thread.Sleep (100) right
after your lblInfo.Refresh ().

--
Tom Shelton [MVP]



这篇关于循环内存消耗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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