Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

delay me.close() 1

Status
Not open for further replies.

Hobeau

MIS
Apr 19, 2004
77
US
hey guys, I have an application that is supposed to play a .wav file as it closes. I got the sound to play and everything, however, on the exit button the my playsound is right before my me.close() so that it starts to play the sound but my project closes before it finishes playing the sound. Can someone tell me how to delay the me.close() or close the project after the sound is completed? Here is some of my code:

Code:
'this is the exit button that exits the program
'and is supposed to play a .wav file as it exits

 Dim snd As SoundClass = New SoundClass
            snd.PlaySoundFile(FILE_NAME)

            Me.Close()
 
I found some code for a very easy sound class (I'm a newbie). it looks something like this:

Code:
Public Class SoundClass
        Declare Auto Function PlaySound Lib "winmm.dll" (ByVal name _
           As String, ByVal hmod As Integer, ByVal flags As Integer) As Integer

        Public Const SND_SYNC = &H0
        Public Const SND_ASYNC = &H1
        Public Const SND_FILENAME = &H20000
        Public Const SND_RESOURCE = &H40004

        Public Sub PlaySoundFile(ByVal filename As String)

            PlaySound(filename, Nothing, SND_FILENAME Or SND_ASYNC)
        End Sub
    End Class

I'm referencing a wav file thats located on my computer. It plays just fine except for the fact that it gets cut off in the middle of the sound because it runs the me.close() before the sound byte has a chance to finish playing.
 
You could try making the sound class operate in it's own thread, then befor the me.close() loop until the thread's state is dead. That's my best guess. Search the forum for "Threading" there's a good walk though on it, and the help in .Net should fill in any holes.

-Rick

----------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top