I am coding a feature in a program where users can edit documents stored in a database, it saves the document to a temporary folder then uses Process.Start to launch the document into the editing application, let's say Microsoft Word for example.
Then my app needs to wait until they've closed the called process and replace the document in the database with the newly edited copy in the temp folder.
The following code works great as long as the called application isn't 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();
Is there a way to force starting a completely new process or can anyone think of another way to handle this. I really don't want the users to be able to do anything else in my app until they've closed the called process because I need to know if they edited that file or not at that point in time, not later when all sorts of other problems could creep up.
Personally I'm not sure I agree with this approach at all. Displaying a modal form might get you out of this situation, but in most cases when a solution seems hard to find, it's helpful to change the problem you're trying to solve.
Option 1:
In this case, I'd recommend a checkout/checkin model. This would allow users to "checkout" a file to their machine, and then check it in when they have finished updating it. This has a number of benefits:
The model also fits well with the concept of creating a new document, and adding it to the database. It's the same as a checkin.
You could easily provide reports that display who has what document checked out, and what their "working copy" location is.
I would concede that typically only developers are comfortable with this model, and that you may have to invest in a small amount of re-training. I don't think it would be difficult to setup an automated reminder system that emails people when they've had a document checked out for a long time.
Option 2:
Watch the file using a FileSystemWatcher or equivalent. This would enable you to keep an eye on the file, and when the user performs a save operation, you can commit to the database. After all, it's only if the user actually saved the file that you're interested in updating the database,
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With