-
Apr 13th, 2013, 12:23 PM
#1
Thread Starter
Banned
new pause funchion
Code:
Private Sub TimeOut(HowLong)
Dim TheBeginning
Dim NoFreeze As Integer
TheBeginning = Timer
Do
If Timer - TheBeginning >= HowLong Then Exit Sub
NoFreeze% = DoEvents()
Loop
End Sub
use
TimeOut 4
-
Apr 13th, 2013, 08:44 PM
#2
Re: new pause funchion
Would this require you to actually place a timer on the form?
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
Apr 13th, 2013, 10:29 PM
#3
Re: new pause funchion
I appreciate what you're trying to do but that is a terrible way to do it and noone should ever use code like that. What you have there is called a "busy wait loop". What that means is that, in order to get your app to do nothing, you have it hitting the system at 100%. While that loop is running your processor will be running at 100% capacity. That's bad, bad, bad! If you want your app to do nothing then it should actually do nothing.
You can call Thread.Sleep to pause and do nothing but that is a problem because it means that the UI will lock up for that period. You're obviously trying to provide a way to avoid that lock up but it is misguided. If you want to pause without freezing the UI then you simply do not call a synchronous method. For one off cases, you can simply use a Timer. The code you want performed before the pause goes where it usually would and then you call Start on the Timer to pause. That should be the end of that method and the code you want executed after the pause would go in the Tick event handler of the Timer, after a call to Stop. Where using your method might look like this:
Code:
Private Sub DoWork()
DoSomething()
TimeOut(5000)
DoSomethingElse()
End Sub
using a Timer would look like this:
Code:
Private Sub DoWork()
DoSomething()
Timer1.Start()
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Timer1.Stop()
DoSomethingElse()
End Sub
It may take a little more code but you should never use a hack to avoid writing a little bit of code. If you want something a bit more general purpose then you could easily create a class that provided the functionality.
-
Apr 13th, 2013, 11:39 PM
#4
Frenzied Member
Re: new pause funchion
Originally Posted by jmcilhinney
I appreciate what you're trying to do but that is a terrible way to do it and noone should ever use code like that. What you have there is called a "busy wait loop". What that means is that, in order to get your app to do nothing, you have it hitting the system at 100%. While that loop is running your processor will be running at 100% capacity. That's bad, bad, bad! If you want your app to do nothing then it should actually do nothing.
You can call Thread.Sleep to pause and do nothing but that is a problem because it means that the UI will lock up for that period. You're obviously trying to provide a way to avoid that lock up but it is misguided. If you want to pause without freezing the UI then you simply do not call a synchronous method. For one off cases, you can simply use a Timer. The code you want performed before the pause goes where it usually would and then you call Start on the Timer to pause. That should be the end of that method and the code you want executed after the pause would go in the Tick event handler of the Timer, after a call to Stop. Where using your method might look like this:
Code:
Private Sub DoWork()
DoSomething()
TimeOut(5000)
DoSomethingElse()
End Sub
using a Timer would look like this:
Code:
Private Sub DoWork()
DoSomething()
Timer1.Start()
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Timer1.Stop()
DoSomethingElse()
End Sub
It may take a little more code but you should never use a hack to avoid writing a little bit of code. If you want something a bit more general purpose then you could easily create a class that provided the functionality.
Original post looks like VB6.
But in vbNet, couldn't you use System.Threading.Thread.Sleep(timeout)
-
Apr 14th, 2013, 03:35 AM
#5
Re: new pause funchion
Originally Posted by Zach_VB6
Original post looks like VB6.
But in vbNet, couldn't you use System.Threading.Thread.Sleep(timeout)
Thread.Sleep will create a genuine pause but the issue there is that it blocks the current thread. If you call Thread.Sleep on the main thread of a GUI app then you freeze the UI. The fact that a variable in the original code is called 'NoFeeze', this code is intended to avoid that. You might like to check this out:
http://www.vbforums.com/showthread.p...e-to-Your-Code
-
Apr 15th, 2013, 05:57 AM
#6
Re: new pause funchion
Moved to the VB6 CodeBank.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|