views:

99

answers:

4

hi,

i have a program in c# which run some process for example

        generate.exe a.tif -o myfile.txt

and the next line after the following my code will need to access the following myfile.txt. how do i know when it is ready? i know that it will generate the file for sure, but how to set the next line so that it executes only after the file myfile.txt is generated. thanks a lot!!!

+4  A: 

Try: Process.WaitForExit

Naveen
Will work only when process exits after generating file
aJ
+1  A: 

Assuming that your process exits only after generating the file you can use Process.WaitForExit()

You can check also this kb article for more information: http://support.microsoft.com/kb/305369

pj.az109
+1  A: 

If the process ends right after creating the file then you can use Process.WaitForExit as @Naveen suggested. If process does not end then:

  1. Either you will have to introduce the IPC ( ex: events) to indicate the file creation.
  2. Or Poll the file creation by opening at some fixed amount of time. ( weak solution,I believe).
aJ
A: 

Process.HasExited will give you the answer you are looking for.

Matt