?
Solved

CreateProcess and WaitForSingleObject fails on the second of two PDF files

Posted on 2009-04-14
2
Medium Priority
?
552 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 7

Accepted Solution

by:
ahalya earned 1500 total points
ID: 24175000
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
ID: 31570197
ahalya
Thanks for that. I added the /n switch to Acro32.exe and it solved the problem.

Regards

Bob
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses
Course of the Month13 days, 4 hours left to enroll

777 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