Results 1 to 2 of 2
2004-03-26, 18:56 #1
- Join Date
- Jan 2001
- Serbia and Montenegro (Yugoslavia)
- Thanked 0 Times in 0 Posts
Forcing subroutine to hold while processing (VB6/Windows Media Player 8/9)
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
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.
2004-03-26, 22:26 #2
- Join Date
- Mar 2002
- Thanked 30 Times in 30 Posts
Re: Forcing subroutine to hold while processing (VB6/Windows Media Player
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 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.