|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Do loop memory consumption?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 wrote:
Show quoteHide quote > The Timer loop below consumes all available CPU time from my development PC. One way to fix this would be to insert System.Thread.Sleep (100) right> 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 after your lblInfo.Refresh (). -- Tom Shelton [MVP] 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 Show quoteHide quote "Tom Shelton" <t**@mtogden.com> wrote in message news:1146002783.330291.234260@j33g2000cwa.googlegroups.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] > Insert an "Application.DoEvents: to allow for other proccesses to run. And
then in the btnStop's click event, stop the timer. james Show quoteHide quote "Bill Nguyen" <billn_nospam_please@jaco.com> wrote in message news:%23TKG6oLaGHA.3444@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" <t**@mtogden.com> wrote in message > news:1146002783.330291.234260@j33g2000cwa.googlegroups.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] >> > > Bill Nguyen wrote:
> Tom; Hello Bill,> > 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? > 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. This will definitely help!
My thanks to all of you in this thread. Bill Show quoteHide quote "ShaneO" <shane***@optusnet.com.au> wrote in message news:444ecf49$0$3341$afc38c87@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. > I need to interrupt the loop when user presses the STOP button. The problem That's exactly why you shouldn't sleep on a UI thread. And DoEvents>that btnStop(on the same form) is not accessible during the loop. 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. 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. I'm willing to learn.
Can you please give me a sample code? Thanks Bill Show quoteHide quote "Mattias Sjögren" <mattias.dont.want.spam@mvps.org> wrote in message news:%23360uiLaGHA.4248@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. "Bill Nguyen" <billn_nospam_please@jaco.com> wrote in For stuff like this... you should be using a Windows Timer to process news:uC21kBLaGHA.5088@TK2MSFTNGP03.phx.gbl: > 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. repeatitve GUI events. > For stuff like this... you should be using a Windows Timer to process Serious why, I have the idea that once somebody wrote this on a blog and no > repeatitve GUI events. everybody is parroting it. In my opinion is for UI (forms) application the forms timer excellent. But I can be wrong. Cor Cor >In my opinion is for UI (forms) application the I was under the impression that Bill's code is in a winforms>forms timer excellent. 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. > Forget it, I just misreaded your messages, we agree completely.>>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. > Sorry :-) Cor"Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in There are 3 timers in .NET - each one for a specific use.news:uHinjNPaGHA.4916@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. 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. 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. Show quoteHide quote "Spam Catcher" <spamhoneypot@rogers.com> schreef in bericht news:Xns97B1843E472C7usenethoneypotrogers@127.0.0.1... > "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in > news:uHinjNPaGHA.4916@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. "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in NP, I read your other posts in other groups and they're usually pretty news:#v51TXVaGHA.4160@TK2MSFTNGP04.phx.gbl: > 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. accurate so I knew it was probably a misunderstanding : ) > For stuff like this... you should be using a Windows Timer to process Why? see for the rest my reply to Mattias.> repeatitve GUI events. Cor > The Timer loop below consumes all available CPU time from my development PC. Use Thread.Sleep to make a delay without using CPU time.> 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.
"Send To Mail Recipient"
Saving outlook email attachment? ListBox Control Recursion with a Tree View and checkboxes GetType question Click-Once Deployment of DLLs Automatically interacting with a search engine... Getting property settings for controls in the immidiate window in VB2005 OnPaint vs. using a cached background image crystal report viewer connection |
|||||||||||||||||||||||