• Forcing subroutine to hold while processing (VB6/Windows Media Player 8/9)

    Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » Forcing subroutine to hold while processing (VB6/Windows Media Player 8/9)

    Author
    Topic
    #402889

    Have an application that loops through a directory holding several MPG movies that I want to convert to WMF files. It works but when it spawns the encoder, the method I wrote needs to wait until the encoder completes, otherwise it will convert only a few KB’s and stop. I tried usingthe following to hold the process until it completes:

    Do While Encoder.RunState = WMENC_ENCODER_STATE.WMENC_ENCODER_RUNNING

    If Encoder.RunState WMENC_ENCODER_RUNNING Then
    Debug.Print Encoder.RunState
    MsgBox “Done”
    End If

    Loop

    ConvertFile = True

    What ends up happening is that it will stay hung in that loop until I do a break or something, when I restart it it will start processing the next. If I look at the files in the directory it is converting to I see the file names changing but at a certain point it just hangs (I think), yet still taking up 100% of my CPU.

    Viewing 0 reply threads
    Author
    Replies
    • #805521

      First, try inserting a DoEvents instruction in the loop; this gives other processes (such as the encoder) a chance to do something.

      If that doesn’t help, the API functions CreateProcess and WaitForSingleObject might help. See http://www.mentalis.org/apilist/CreateProcess.shtml%5B/url%5D for info on CreateProcess; it contains a link to an example named SuperShell that demonstrates how to use it together with WaitForSingleObject to let your code wait till a called program has finished executing.

    Viewing 0 reply threads
    Reply To: Forcing subroutine to hold while processing (VB6/Windows Media Player 8/9)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: