views:

798

answers:

1

All

I use CreateProcess and WaitForSingleObject in Delphi 2007 to open files and wait for them to be closed. I have found that when I open two PDF files in a row, the second WaitForSingleObject returns immediately. I have also found that this happens for jpg and tif files but not txt files. Also the second PDF takes 10 seconds longer to open than if opened by itself! It also happens on both Vista and XP, and on a range of computers. Am I using CreateProcess incorrectly or is it something else?

Any help would be appreciated.

Regards

Bob

+2  A: 

What happens depends on the application that is registered to open PDF or JPG files. If you open the documents in an SDI application, then every CreateProcess() call returns a process handle for an application, which you can wait for - this will return when the application editing the document closes.

If however an application is limited to a single instance, then every further call will return as soon as the new instance has passed the data to the first instance (which will usually open the document in a new frame), and then has exited. I think that is what happens in your case, probably you are using Acrobat Reader to open the PDF files?

mghie