Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > Pause / Sleep / Timer ?


Reply
 
Thread Tools Display Modes
  #1  
Old 09-17-2002, 03:11 PM
chrishan chrishan is offline
Newcomer
 
Join Date: Aug 2002
Posts: 20
Question Pause / Sleep / Timer ?


I currently use a function:

Public Function pause(Seconds)
Dim Start

Start = Timer ' Set start time.

Do While Timer < Start + Seconds
DoEvents ' Yield to other processes.
Loop
End Function

However the problem I see is this racks up the cpu to 100%. I then tried using sleep:

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

however this tells the whole app to sleep and I am unable to use any of the controls.

My question is does anyone have a suggestion on how to pause execution for X seconds, allowing for other controls to be hit, which doesnt suck the cpu dry?

Thanks
Reply With Quote
  #2  
Old 09-17-2002, 03:13 PM
Iceplug's Avatar
Iceplug Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: California, USA
Posts: 16,583
Default

Have you tried adding a DoEvents before your sleep call?
You could also partition your sleep calls to
DoEvents
Sleep 100
DoEvents
Sleep 100
etc...
I haven't tried it, but it should work, somewhat... .
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #3  
Old 09-17-2002, 03:15 PM
chrishan chrishan is offline
Newcomer
 
Join Date: Aug 2002
Posts: 20
Default

I have tried using the DoEvents before the sleep however once sleep occurs it locks the controls and if I was to space them apart like that I would have miliseconds to hit the control before it was locked again. Thanks for the suggestion
Reply With Quote
  #4  
Old 09-17-2002, 03:21 PM
BillSoo's Avatar
BillSoo BillSoo is offline
Code Meister

Retired Moderator
* Guru *
 
Join Date: Aug 2000
Location: Vancouver, BC, Canada
Posts: 10,441
Default

Personally, I don't see the problem with running the CPU up to 100%.... after all, if you have any other process running, it will get it's share of time anyways so all you are doing is using up time that would be wasted.

But if you insist, you can try using the WaitForSingleObject function....I haven't used it myself...
__________________
"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder
Reply With Quote
  #5  
Old 09-17-2002, 03:23 PM
chrishan chrishan is offline
Newcomer
 
Join Date: Aug 2002
Posts: 20
Default

Thanks, I will give that a try. Personally I am not to concerned about what the montor shows being used since it has little affect on the machine, however one of the managers here at my work is having a fit about seeing the cpu at 100% for any given period of time, no matter how much I explain it isnt taking away from the other applications. Oh well what can you do Quit
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->