0

I have a c# program, integrated with a command line program. I want to run the command line program twice(start, finish, start again, finish again). Now I use a timer to set a special time period for every run, for example, give first run 10 seconds, no matter it is finished or not, after 10 seconds, the program starts the second run.

I want the second run can run automatically after the fist run finshed, How to do it? How to detect the first run is finished, and then take a trigger to start the second run?

dsfg
  • 29
  • 1
  • 5
  • Any code snippet will help us.... – ekostadinov Sep 02 '14 at 08:00
  • Do you want to run one instance of the `c#` program which executes a batch twice, or a `cmd` program` that runs your `c#` program twice, each waiting for the first target program to finish beore the second is started? – Magoo Sep 02 '14 at 08:02

2 Answers2

1

Assume you run the command line as a process, see this answer to check if the process has finished: Find out if a process finished running

if (process.WaitForExit(timeout)) 
{
    // user exited
} else {
    // timeout (perhaps process.Kill();)
}
Community
  • 1
  • 1
zvi
  • 3,677
  • 2
  • 30
  • 48
0

In a command line you can launch this command:

start "" /w will execute the command and wait until it is finished before proceeding.

for %a in (1 2) do start "" /w "programA.exe"
foxidrive
  • 40,353
  • 10
  • 53
  • 68