By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,222 Members | 1,436 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,222 IT Pros & Developers. It's quick & easy.

Delay the execution of a line of code??

P: 1
My program is supposed to play a wav file of a ticking clock using the media player object so that only after the file is over (this is to build tension), some textboxes are populated with data generated in a subroutine called givegroups.

Everything is working fine, except for the fact that the textboxes are being populated as soon as the audio clip starts playing, therefore no tension is being built. I've tried using threading.thread.sleep(10000) by writing it under the subroutine that plays the file (called StartClockTick) but over the subroutine that populates the textboxes (givegroups) with dissapointing results. (it still fills in the textboxes as soon as the audio file starts playing).

How can I make the program to play the whole 10 seconds of audio file, before reading the subroutine "givegroups" that populates the textboxes?

Here is the relevant code:

Private Sub MakeGroupsBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MakeGroupsBtn.Click
Call StartClockTick()
'It loads the audio file to the media player object and plays it.
Call givegroups(playersarray)
'It populted the textboxes in the form. This should happen after the
audio file has been played compeltely (it lasts 9 seconds).
End Sub

Private Sub StartClockTick()
Timer2.Enabled = True
myPlaya.URL = "C:\Documents and Settings\Juan M. Lemus\
MyDocuments\My Music\ClockTick.wav"
End Sub

Private Sub Timer2_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer2.Tick
Dim timeStr, lengthStr As String
timeStr = myPlaya.Ctlcontrols.currentPositionString
lengthStr = myPlaya.currentMedia.durationString
StatusStrip1.Items.Item(1).Text = timeStr & " / " & lengthStr

Dim length As Integer, time As Integer
time = myPlaya.Ctlcontrols.currentPosition
length = myPlaya.currentMedia.duration
If (length > 0) Then
pbrGroups.Value = 100 * (time / length)
End If
End Sub

NB: The timer2 is a timer object used to dynamically update a progress bar that monitors the progress of the audio file.
Sep 4 '07 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.