?
Solved

Staggering EXE's

Posted on 2005-03-04
9
Medium Priority
?
200 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
[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
  • 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
Industry Leaders: 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!

 
LVL 26

Expert Comment

by:EddieShipman
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

Industry Leaders: 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 Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month13 days, 11 hours left to enroll

801 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