1,105,456 Community Members

Pause VB 2012

Member Avatar
JakeRivett
Newbie Poster
5 posts since Oct 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

How do you go about pausing your code from operating. I want to make an animation by making a picture box visable then another then another but I need a period of time between transitions? How would I go about doing this?

boredPic(1, 1).Visible = True
boredPic(1, 1).Image = My.Resources.Red
     'pause for half a second then
boredPic(1, 1).Visible = false
boredPic(2, 1).Visible = True
boredPic(2, 1).Image = My.Resources.Red
    'pause again for half a second
etc 
Member Avatar
hometownnerd
Junior Poster in Training
50 posts since Sep 2007
Reputation Points: 13 [?]
Q&As Helped to Solve: 6 [?]
Skill Endorsements: 4 [?]
 
0
 

You could do something like this...

Dim stpWatchInfo As New System.Diagnostics.Stopwatch

boredPic(1, 1).Visible = True
boredPic(1, 1).Image = My.Resources.Red
     'pause for half a second then
stpWatchInfo.Restart()
while stpWatchInfo.Elapsed.TotalMilliseconds<500
'this is a 500 millisecond pause or 1/2 second

End While

boredPic(1, 1).Visible = false
boredPic(2, 1).Visible = True
boredPic(2, 1).Image = My.Resources.Red
    'pause again for half a second
stpWatchInfo.Restart()
while stpWatchInfo.Elapsed.TotalMilliseconds<500
    'this is a 500 millisecond pause or 1/2 second

End While
etc

That may work for you. let me know if you need more help or it doesn't work correctly.
Larry

Member Avatar
adam_k
Veteran Poster
1,056 posts since Jun 2011
Reputation Points: 239 [?]
Q&As Helped to Solve: 212 [?]
Skill Endorsements: 17 [?]
 
1
 

You use a timer to track time and run the next thing when you want it to.
But... you don't want to "pause" your program or have the timer loop for a period, becuase if I am not mistaken that will freeze your main thread and no animation will show.
Use multi-threading or background worker for the timer and the track of time.
I'm sure you'll find lots of tutorials in here.

Member Avatar
Reverend Jim
Noli mentula
5,445 posts since Aug 2010
Reputation Points: 746 [?]
Q&As Helped to Solve: 653 [?]
Skill Endorsements: 51 [?]
Moderator
Featured
 
0
 

You can pause your application (the example here is for half a second) by

System.Threading.Thread.Sleep(500)

but what would be the point? All that you do is make your app unresponsive for the sleep time. VB programs are event driven. If you want some event to occur at set intervals then create a timer control and set the interval for the appropriate number of milliseconds. Put the code you want to execute in the timer Tick event.

Member Avatar
JakeRivett
Newbie Poster
5 posts since Oct 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Is there a way of playing the timer tick though in the middle of code being run? so the code will stop, run the timer(showing the animation or the picture box) then go back to the code and carry on till the end?

Member Avatar
Reverend Jim
Noli mentula
5,445 posts since Aug 2010
Reputation Points: 746 [?]
Q&As Helped to Solve: 653 [?]
Skill Endorsements: 51 [?]
Moderator
Featured
 
0
 

You have to break up your code into subs. Each sub can be executed when a timer expires. You can't pause your code and have it continue to execute at the same time.

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: