C # Process.Start, how to prevent reuse of an existing application?

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();

- . , - , , , , , .

+5
5

, WaitForExit "Exited event", : , , , , .

, , Process.Start.

.

0

, . , , , , .

1:

checkout/checkin. "" , , . :

  • .
  • .
  • - .
  • , .
  • , , ( ), , .

. , .

, , , " ".

, , , , , . , , , .

2:

FileSystemWatcher . , , . , , , ,

+2

, :

while (Process.IsRunning) {}

, .

0

, "Exited event" process.EnableRisingEvents true. , Exited!

, , , , , , , , - ... .

!

0
source

I think you are using the wrong method to solve the problem. If you are dealing only with text documents, I believe that you should use COM interaction with the word and control word from your application. With COM, you can control the whole word, you can open a document with a word, and you will know when the user closed it.

0
source

All Articles