Solved

CreateProcess and WaitForSingleObject fails on the second of two PDF files

Posted on 2009-04-14
2
546 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 500 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Printing problem 2 124
LAN or WAN ? 11 120
Delphi Ado Query To Converts Joined Columns Into Rows Based on Primary Key 4 93
can i put an image from resource into image tag ? 6 41
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…
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…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

734 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