Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Staggering EXE's

Posted on 2005-03-04
9
Medium Priority
?
202 Views
Last Modified: 2010-04-05
I have a delphi application that executes 2 VB applications from within it. That all works OK but is it possible i can have a line of code within delphi that will fire the first VB application and then count before it fires the second. These applications are launched from the same button, so am looking for a line to put inbetween the 2 executables

Many thanks
0
Comment
Question by:Paul-Brooks
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 15

Accepted Solution

by:
mikelittlewood earned 1500 total points
ID: 13459513
Why not put a timer on the form set for say 10 seconds.
Set a boolean variable to tell you if the first application was fired off, if it was then fire off the second.
0
 
LVL 15

Expert Comment

by:mikelittlewood
ID: 13459529
bFirstApp: Boolean

procedure TForm1.FormCreate(Sender: TObject);
begin
  bFirstApp := False;
end;

procedure TForm1.tmrFireAppTimer(Sender: TObject);
begin
  if not bFirstApp then
  begin
    ShellExecute( // put first app code here )
    bFirstApp := True;
  end
  else
    ShellExecute( // put second app code here )
end;
0
 
LVL 15

Expert Comment

by:mikelittlewood
ID: 13459541
forgot to say set the timer.enabled to False, and then when you hit the button set it true true.
probably an idea to set the bFirstApp to false when you click the button rather than on the form create.
also disable the button one you click it so you dont reset the boolean variable halfway through the timer event.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 26

Expert Comment

by:Eddie Shipman
ID: 13459746
Use the Sleep method:

ShellExecute( Handle, 'open', 'firstvbapp.exe', Nil, Nil, SW_SHOWNORMAL );
Sleep(10000); // number of milliseconds to sleep, 10000 = 10 seconds
ShellExecute( Handle, 'open', ''secondvbapp.exe', Nil, Nil, SW_SHOWNORMAL );
0
 
LVL 13

Expert Comment

by:BlackTigerX
ID: 13460186
...same thing, but showing a count on a label:
var
  X:Integer;
begin
  ShellExecute( Handle, 'open', 'firstvbapp.exe', Nil, Nil, SW_SHOWNORMAL );
  for X:=10 downto 1 do
  begin
    Sleep(1000);
    Label1.Caption:=IntToStr(X) //you need to have a Label on your form to show the counter...
  end;
  ShellExecute( Handle, 'open', ''secondvbapp.exe', Nil, Nil, SW_SHOWNORMAL );
0
 
LVL 5

Expert Comment

by:DeerBear
ID: 13465835
Sleep is a very very very bad choiche, imho, because it's computer dependant.
Better use a timer with a very simple state machine.

Cheers,

Andrew
0
 
LVL 46

Expert Comment

by:aikimark
ID: 13470810
Both solutions (timer and sleep) have their proper uses.  If you want an efficient synchronous mechanism that will stop your Delphi program from consuming any CPU cycles between program launches, you should probably choose SLEEP.  If you want a more asynchronous launching, then starting a timer would be a good choice.
Easiest to implement:
1. timer - asynch Delphi behavior
2. sleep - synch Delphi behavior

These aren't your only choices...
3. use the scheduling mechanism of (recent) Windows versions to let the operating system do the scheduling.
4. monitor the activity of the first program (looking at an output/log file) to determine the best time to launch the second program
5. base the inter-program launch interval on the relative clock speeds of different systems.  Faster systems require smaller intervals and vice versa.
6. let the first VB program launch the second VB program...requires VB coding -- yuck :-(  
7. look at the capabilities of the CPU and launch both programs on different CPUs if running on a dual processor chipset
8a. place invocation statments into a .cmd/.bat file and shell the .cmd/.bat file with your Delphi program.  This will allow you to run the VB programs sequentially.
8b. monitor the first VB program's Windows process and launch the second VB program after the first one has finished.  This will allow you to run the VB programs sequentially.

============================
An important piece of missing information is why you need to stagger the start of these two VB programs.  
* resource availability
* resource contention
* application processing logic
* other reasons

Secondarily, do you have any influence over the behavior of these VB programs?  If they are CPU cycle hogs, then they should execute DoEvent statements at regular intervals in their loops.
0
 
LVL 5

Expert Comment

by:DeerBear
ID: 13471002
If you have to wait for an app to end before starting the other, the optimal solution is a combination of WaitForSingleObject and CreateProcess.

cheers,

Andrew
0
 
LVL 46

Expert Comment

by:aikimark
ID: 13531496
Paul-Brooks,

Are you still with us?  We haven't heard from you in a week.
0

Featured Post

Independent Software Vendors: 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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…
Suggested Courses
Course of the Month11 days, 21 hours left to enroll

564 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