473,511 Members | 9,983 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Do loop memory consumption?

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
Apr 25 '06 #1
14 1614

Bill Nguyen wrote:
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


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

--
Tom Shelton [MVP]

Apr 25 '06 #2
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.
Apr 25 '06 #3
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 wrote:
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


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

--
Tom Shelton [MVP]

Apr 25 '06 #4
Insert an "Application.DoEvents: to allow for other proccesses to run. And
then in the btnStop's click event, stop the timer.
james

"Bill Nguyen" <bi*****************@jaco.com> wrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
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 wrote:
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


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

--
Tom Shelton [MVP]


Apr 26 '06 #5
Bill Nguyen wrote:
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?


Hello Bill,

I'd consider changing you code as follows (Watch for line-wrapping) -

Dim blExitLoop as Boolean = False 'Place this in General Declarations
Section

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 And blExitLoop
= False
t += 1
lblInfo.Text = "test timer -> " & t
'lblInfo.Refresh() 'You can REMOVE this now!
System.Threading.Thread.Sleep(100)
System.Windows.Forms.Application.DoEvents()

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

(Note the change to your "Do While... Loop above!)

I'd then put the following in your "Stop" Button Click Event -

blExitLoop = True
I hope this helps.

ShaneO

There are 10 kinds of people - Those who understand Binary and those who
don't.
Apr 26 '06 #6
This will definitely help!
My thanks to all of you in this thread.

Bill
"ShaneO" <sh******@optusnet.com.au> wrote in message
news:44**********************@news.optusnet.com.au ...
Bill Nguyen wrote:
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?


Hello Bill,

I'd consider changing you code as follows (Watch for line-wrapping) -

Dim blExitLoop as Boolean = False 'Place this in General Declarations
Section

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 And blExitLoop =
False
t += 1
lblInfo.Text = "test timer -> " & t
'lblInfo.Refresh() 'You can REMOVE this now!
System.Threading.Thread.Sleep(100)
System.Windows.Forms.Application.DoEvents()

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

(Note the change to your "Do While... Loop above!)

I'd then put the following in your "Stop" Button Click Event -

blExitLoop = True
I hope this helps.

ShaneO

There are 10 kinds of people - Those who understand Binary and those who
don't.

Apr 26 '06 #7
For stuff like this... you should be using a Windows Timer to process
repeatitve GUI events.


Serious why, I have the idea that once somebody wrote this on a blog and no
everybody is parroting it. In my opinion is for UI (forms) application the
forms timer excellent.

But I can be wrong.

Cor

Cor
Apr 26 '06 #8
For stuff like this... you should be using a Windows Timer to process
repeatitve GUI events.


Why? see for the rest my reply to Mattias.

Cor
Apr 26 '06 #9
> 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.


Use Thread.Sleep to make a delay without using CPU time.
Apr 26 '06 #10
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.


That's exactly why you shouldn't sleep on a UI thread. And DoEvents
has its own problems. Again, try it with a timer.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Apr 26 '06 #11
In my opinion is for UI (forms) application the
forms timer excellent.


I was under the impression that Bill's code is in a winforms
application. So I'm not sure if you're disagreeing with us or what
your point is.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Apr 26 '06 #12
>
In my opinion is for UI (forms) application the
forms timer excellent.


I was under the impression that Bill's code is in a winforms
application. So I'm not sure if you're disagreeing with us or what
your point is.

Forget it, I just misreaded your messages, we agree completely.

Sorry

:-)

Cor
Apr 26 '06 #13
Spam Catcher,

The same as to Mattias,

I misreaded your messages I thougt you were pointing to the
system.systems.timer as I had seen done more, while the forms timer is in my
idea sufficient in this case.

So I thought maybe they have a reason for that and than I want to know why.

Sorry,

Cor.

"Spam Catcher" <sp**********@rogers.com> schreef in bericht
news:Xn**********************************@127.0.0. 1...
"Cor Ligthert [MVP]" <no************@planet.nl> wrote in
news:uH**************@TK2MSFTNGP04.phx.gbl:
Serious why, I have the idea that once somebody wrote this on a blog
and no everybody is parroting it. In my opinion is for UI (forms)
application the forms timer excellent.


There are 3 timers in .NET - each one for a specific use.

So Timers could be used in forms, in server code, or as a general timer.
Depends on which class and which scenario.

Better than having a constant loop.

Of course it depends on the situation - some things are better suited for
a
thread looping and others for a timer.

Apr 26 '06 #14
I'm willing to learn.
Can you please give me a sample code?
Thanks

Bill

"Mattias Sjögren" <ma********************@mvps.org> wrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
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.

Apr 27 '06 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
1912
by: Andy | last post by:
Along with many others I've noticed the large amount of memory that can be taken up by the aspnet_wp.exe. I've found that I can better control and limit this memory consumption by including a...
1
1350
by: anandav2001 | last post by:
Hello developers, I have created an executable(system tray application) in VS.net 2003 using VB.net. My app was taking 30 MB memory(since some web services call are there which happens for each...
7
6914
by: Salvador | last post by:
Hi, I am using WMI to gather information about different computers (using win2K and win 2K3), checking common classes and also WMI load balance. My application runs every 1 minute and reports...
8
2816
by: Raja Gregory | last post by:
Hi All, I have developed a server application in C#. While running this application, it is not running more than 30 minutes due to memory leak. Could you tell me what will be the problem?
9
5188
by: Adam Right | last post by:
Hi, Anyone suffers from the high memory usage of C# in windows applications? Is there a solution for that problem? Thanks...
12
8436
by: Tony | last post by:
Hi expert, I installed DB2 v8.2 server on Solaris 9 box. When I connect to DB2 using control centre or other applications(except command line), around 12 db2sysc processes pop up and each one...
1
2307
by: buu | last post by:
It's strange to me, but, create a dictionary and fill it with 1 mil. of some objects. then, see the memory consumption (arised, of course). then, clean the dictionary.... memory consumption is...
10
2277
by: deciacco | last post by:
I'm writing a command line utility to move some files. I'm dealing with thousands of files and I was wondering if anyone had any suggestions. This is what I have currently: $arrayVirtualFile =...
17
7931
by: Cesar | last post by:
Hello people. I'm having a Winform app that contains a webbrowser control that keeps navigating from one page to another permanentrly to make some tests. The problem I'm having is that after a...
0
7148
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7430
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7089
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7517
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5673
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5072
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4743
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1581
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
790
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.