H2O
H2O

Reputation: 592

Can we use a timer for itself?

Actually this is what i want to do;

When a condition appears, my program will close itself and after five minutes it will re-open.

Is it possible with only one .exe -by using any OS property-?

I do it with two .exe

if (close_condition){
     //call secondary program
     system ("secondary.exe");
     return (0);
}

and my secondary program just waits for five minutes and calls the primary one.

main (){
     Sleep (300000)//sleep for five minutes;
     system ("primary.exe");
     return (0);
}

i want to do it without secondary program.

(sorry for poor english)

Upvotes: 0

Views: 95

Answers (2)

Georg Fritzsche
Georg Fritzsche

Reputation: 98964

You can do it with one application that simply has different behaviour if a switch is given (say myapp.exe /startme).

system() is a synchronous call by the way, it does only return when the command run is finished. In win32 CreateProcess() is what you are looking for.

You can also just follow Jays suggestion of letting the OS schedule your job using NetScheduleJobAdd().

But, depending on what you're trying to achieve, a better solution might be to simply hide your application for 5 minutes.

Upvotes: 3

Jay
Jay

Reputation: 57899

I think you'd have to use the system task scheduler to schedule the re-launch, which in a sense is using another application, but one that is part of the OS.

I'm sure this can be done, but frankly I think you should just stick with your current setup.

Upvotes: 1

Related Questions