Solved

CreateProcess and WaitForSingleObject fails on the second of two PDF files

Posted on 2009-04-14
2
535 Views
Last Modified: 2012-05-06
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

if CreateProcess(nil, PChar(sText), nil, nil, False,

    NORMAL_PRIORITY_CLASS, nil, pFilePath, myStartupInfo, myProcessInfo) then begin

    WaitForSingleObject(myProcessInfo.hProcess, INFINITE);

    CloseHandle(myProcessInfo.hProcess);

    CloseHandle(myProcessInfo.hThread);

end;

Open in new window

0
Comment
Question by:beezee
2 Comments
 
LVL 7

Accepted Solution

by:
ahalya earned 500 total points
Comment Utility
I guess what probably is happening is that your second call creates a second instance of Acrobact Reader, which is terminating immediately  (once it figures out a previous instance is running). The second instance probably is passing the file name to the first instace of the Acrobat Reader which opens the file (but is a separate process).

Your wait returns when the second process is terminated after passing the filename

0
 

Author Closing Comment

by:beezee
Comment Utility
ahalya
Thanks for that. I added the /n switch to Acro32.exe and it solved the problem.

Regards

Bob
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This video discusses moving either the default database or any database to a new volume.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now