I encode a function in a program where users can edit documents stored in a database, it saves the document in a temporary folder, and then uses Process.Start to start the document in an editing application, for example, Microsoft Word.
Then my application needs to wait until they close the called process and replace the document in the database with a new edited copy in the temp folder.
The following code works fine while the called application is not already running:
ProcessStartInfo pInfo = new ProcessStartInfo();
pInfo.FileName=TempFolder + Path.DirectorySeparatorChar + f.Name;
Process p = new Process();
p.StartInfo = pInfo;
p.Start();
//p is null at this point if called application was already running
//i.e. Microsoft Word is re-used instead of starting a fresh copy
p.WaitForInputIdle();
p.WaitForExit();
- . , - , , , , , .