Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

delay

Status
Not open for further replies.

nnmmss72

Programmer
May 14, 2006
110
IR
i have a program which runs two exe file (file1.exe, file2.exe) one after each other .i want to write another program which delay between execution of these two file some thing like this
file1.exe
delay.exe for 10 seconds
file2.exe

i don't have the source of the programs which executes these file. the delay.exe file should be somehow which does let the file2.exe be executed after 10 seconds.any idea?
 
Create a new project
Delete the default form
Add a module with the following code:
Code:
[blue]
Option Explicit

Private Sub main()
    Dim starttime As Date
    
    starttime = Now
    Do Until DateDiff("s", starttime, Now) >= 10
        DoEvents
    Loop
    Shell "realfile2.exe"
End Sub[/blue]
Set the Project's startup to Sub Main
Compile the program to whatevewr exe you like (I'll use "proxiefile2.exe")
Put it in the same folder as file2.exe
Rename file2.exe as realfile2.exe
Rename proxiefile2.exe as file2.exe
 
actually the problem isn't like that. supoose there is a programe named "master.exe". it reads an ini file and start running whatever is in there suppose i have two line in that ini file
File1=file1.exe
File2=file2.exe

i want to have delay.exe to put it between File1 and File to cause not let the master.exe ,executes file2 just for a few seconds. i don't have the source codes of master.exe. and also file1 and file2, i should do whatever i should in delay.exe.
is that possible?
 
Yes

That's exactly what it does.


To make it more obvious what I'm doing:

Change

Shell "realfile2.exe"
to
Shell "file2.exe"


then compile the example to delay.exe
change the ini file so that it reads

File1=file1.exe
File2=delay.exe

 
Nope, use the sleep API. It wont chew your processor...

(Praise to the KPD Team)
Code:
'This project needs a button
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Sub Command1_Click()
    'KPD-Team 1998
    'URL: [URL unfurl="true"]http://www.allapi.net/[/URL]
    'E-Mail: KPDTeam@Allapi.net
    Me.Caption = "Your system will sleep 5 sec."
    'Sleep for 5000 milliseconds
    Sleep 5000
    Me.Caption = ""
End Sub
Private Sub Form_Load()
    Me.Caption = ""
    Command1.Caption = "Sleep ..."
End Sub
 
Yep, Sleep is kinder than DoEvents - and there are APIs which are allow sleeping whilst still responding to certain events, thus providing the benefits of both techniques (e.g. WaitForSingleObjectEx). However, for this particular question the method of pausing for 10 seconds, whilst of academic interest, is less important here than how we insert the delay given that the OP does not have control of the scheduling application, nor of the two applications it runs
 
strongm,

After reading back my last post, I realise I could have worded it better, it was not meant to sound the way it reads!! You've helped me out far too many times for me to critise you - I hadn't read the OP closely enough and jumped in both feet first (as usual... ;-)).

I'd suggest the OP re-writes a new master.exe using WaitForSingleObjectEx (as you mentioned) to force the "sub-apps" to run synchronously.

I presume that the current sceduling app is simply shelling the apps in turn so they're running concurrently and file1.exe isn't getting a chance to finish it's stuff. Either way, since he has no source-code, it's gonna mean a new app from scratch anyway, so I'd have thought the API would be the way to go.

 
No worries. I didn't take it the wrong way.

>it's gonna mean a new app from scratch

Ah - but no, it doesn't, not if you follow the idea I've outlined.

(and I'm guessing from the original question that the OP is not in a position to rewrite the sceduling app anyway)
 
No worries. I didn't take it the wrong way.
Thanks:)

heh, but both solutions are new apps...;) I was simply suggesting that (unless the master.exe is doing something fancy as well are firing the "sub-apps") it would be less expensive to use the API.

(and I'm guessing from the original question that the OP is not in a position to rewrite the scheduling app anyway)
Yeah, in which case no solution will be truely elegant anyway! :-D

Reconcidering WaitForSingleObject, I've realised I'd assumed (note to self: never asssume, idiot!) that file1.exe would close before file2.exe should launch. However, if file1.exe is going to continue running, it would be fairly much useless anyway!
 
>WaitForSingleObject

Well, I was just thinking of using it (or rather WaitForSingleObjectEx) to make a more flexible Sleep function, rather than to wait on File1 closing ...
 
heh, well we're walking into API territory now... You're far more knowledgable here... (I tend to employ the use of machette's here ;-)) I've only really seen WaitForSingleObjectEx used to launch an app and stop processing until the called app closes. Now I've done some more research, I see that you can simply set a n-second timeout on it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top