tags:

views:

60

answers:

2

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)

+1  A: 

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.

Jay
+3  A: 

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.

Georg Fritzsche
I was also about to say that: hide the application for 5 minutes and reinitalize all related variables and start over.
Donotalo
hiding the app isn't a solution for me, but thanks i solved it with using task scheduler
H2O