hi friends,,,,,
i am doing an gaming project in vb.net 2008..
my problem is i wrote code to play the video in button click,,
so codes after the video playing code in button click must stop for 5 seconds....
how to do it????
i cant use threading.thread.sleep(5000)
if i use that then entire program execution will stop for 5 seconds
if i use that then video will also stop playing.........

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        AxWindowsMediaPlayer1.URL = "c:\vids\a.avi"
        AxWindowsMediaPlayer1.Ctlcontrols.play()
        '(here i need 5 seconds break to execute remaining code(at this time video will play in form)
        label1.text = "finished playing"
        ------------------------------
        -----------------------------
        -------------------------
        '(here 100's of code is there)
        --------------------------
        --------------------
    End Sub

somebdy plz help me
i am struck in college project..........

You can use Timer Control for this. Just add timer and set its interval to 5000(5 Second). Now when play button clicked just play the video and start the timer.

Timer1.Start()

Now in timers event just write this

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
'Your else code here
Timer1.Stop()
    End Sub

or simply split the whole code into two diff Subs one for before video play and another for after. So in button1 click call first Sub and Start the timer and in timer tick event call second Sub and stop the timer...

thx for your reply........
but its not working.....
bcz when we put 1 timer
codes inside the timer will exicute independently
at the same time remaining code after the timer1.start() will also exicute simultaniusly

ok you can do like this , use a timer as king said , but do this

' declare a variable 
dim myDelay as boolean = false 

'now here is ur code 
        AxWindowsMediaPlayer1.URL = "c:\vids\a.avi"
        AxWindowsMediaPlayer1.Ctlcontrols.play()
'start your timer here 
timer1.enable = true 
timer .interval = 5000
'use a while loop
while mydelay = false
 End While
label1.text = "finished playing"


'now use this at the timer tick event 
myDelay = true 
timer1.enable = false

this is not a ideal solution , but this will work for you :)

Regards

thx for your reply........
but its not working.....
bcz when we put 1 timer
codes inside the timer will exicute independently
at the same time remaining code after the timer1.start() will also exicute simultaniusly

Did you use Timer1.Stop()???

thx
i just tried
but its not working
if i do that,,
video will stop playing.....
dnt k.ow how's this windiws media player working......??

Maybe it works like this

Public Class Form1
Dim break as integer = 0

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
AxWindowsMediaPlayer1.URL = "c:\vids\a.avi" AxWindowsMediaPlayer1.Ctlcontrols.play()

        '(here i need 5 seconds break to execute remaining code(at this time video will play in form)
break = 1
Timer1.Start()
If break = 0 Then
   Timer1.Stop()

        label1.text = "finished playing"

        ------------------------------

        -----------------------------

        -------------------------

        '(here 100's of code is there)

        --------------------------

        --------------------
    End If

    End Sub

Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
break = 0
End Sub

Edited 4 Years Ago by Ezzaral: Added code tags. Please use them to format any code that you post.

This article has been dead for over six months. Start a new discussion instead.